WebMethod public string CopyRiderDetailsPict ure string riderdetailsid

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
[WebMethod]
public string CopyRiderDetailsPicture(string riderdetailsid)
{
string status = "OK";
annotation ContactPicture = null;
annotation RiderDetailsPicture = null;
try
{
ColumnSet cs = new ColumnSet();
cs.Attributes = new string[] { "new_riderid", "new_pictureid" };
new_riderdetails riderdetails = (new_riderdetails)CrmConnector.CrmService.Retrieve(EntityName.new_riderdetails.ToString(), new Guid(riderdetailsid), cs);
if (riderdetails.new_riderid != null && riderdetails.new_pictureid != null && riderdetails.new_pictureid != String.Empty)
{
RiderDetailsPicture = (annotation)CrmConnector.CrmService.Retrieve(EntityName.annotation.ToString(), new Guid(riderdetails.new_pictureid), new AllColumns());
ColumnSet cs1 = new ColumnSet();
cs1.Attributes = new string[] { "new_pictureid" };
contact contact = (contact)CrmConnector.CrmService.Retrieve(EntityName.contact.ToString(), riderdetails.new_riderid.Value, cs1);
if (contact.new_pictureid == null || contact.new_pictureid == String.Empty)
{
ContactPicture = new annotation();
ContactPicture.objectid = new Lookup();
ContactPicture.objectid.Value = riderdetails.new_riderid.Value;
ContactPicture.objectid.type = EntityName.contact.ToString();
ContactPicture.isdocument = new CrmBoolean();
ContactPicture.isdocument.Value = true;
ContactPicture.objecttypecode = new EntityNameReference();
ContactPicture.objecttypecode.Value = EntityName.contact.ToString();
ContactPicture.subject = CONTACT_PICTURE;
}
else
{
try
{
ContactPicture = (annotation)CrmConnector.CrmService.Retrieve(EntityName.annotation.ToString(), new Guid(contact.new_pictureid), new AllColumns());
}
catch (Exception ex)
{
ContactPicture = new annotation();
ContactPicture.objectid = new Lookup();
ContactPicture.objectid.Value = riderdetails.new_riderid.Value;
ContactPicture.objectid.type = EntityName.contact.ToString();
ContactPicture.isdocument = new CrmBoolean();
ContactPicture.isdocument.Value = true;
ContactPicture.objecttypecode = new EntityNameReference();
ContactPicture.objecttypecode.Value = EntityName.contact.ToString();
ContactPicture.subject = CONTACT_PICTURE;
}
}
ContactPicture.filesize = new CrmNumber();
ContactPicture.filename = RiderDetailsPicture.filename;
ContactPicture.filesize.Value = RiderDetailsPicture.filesize.Value;
ContactPicture.documentbody = RiderDetailsPicture.documentbody;
if (ContactPicture.annotationid != null)
{
TargetUpdateAnnotation trgAnnotation = new TargetUpdateAnnotation();
trgAnnotation.Annotation = ContactPicture;
UpdateRequest updAnnotation = new UpdateRequest();
updAnnotation.Target = trgAnnotation;
UpdateResponse updrAnnotation = (UpdateResponse)CrmConnector.CrmService.Execute(updAnnotation);
contact.new_pictureid = ContactPicture.annotationid.Value.ToString();
}
else
{
TargetCreateAnnotation trgAnnotation = new TargetCreateAnnotation();
trgAnnotation.Annotation = ContactPicture;
CreateRequest crAnnotation = new CreateRequest();
crAnnotation.Target = trgAnnotation;
CreateResponse crrAnnotation = (CreateResponse)CrmConnector.CrmService.Execute(crAnnotation);
contact.new_pictureid = crrAnnotation.id.ToString();
}
TargetUpdateContact trgContact = new TargetUpdateContact();
trgContact.Contact = contact;
UpdateRequest updReq = new UpdateRequest();
updReq.Target = trgContact;
UpdateResponse updResp = (UpdateResponse)CrmConnector.CrmService.Execute(updReq);