public async Task <IncidentInfo> AddComment(string id, string userId, string comment, string attachUrl) { if (client == null) { Connect2DocDb(); } if (info != null && client != null) { var cases = from c in client.CreateDocumentQuery(docDbUrl) where c.Id.ToUpper().Contains(id.ToUpper()) select c; IncidentInfo issue = null; Document oDoc = null; foreach (var cs in cases) { var it = await client.ReadDocumentAsync(cs.AltLink); oDoc = it; issue = (IncidentInfo)(dynamic)it.Resource; break; } if (oDoc != null) { Comment c = new Comment(); c.AttachmentUrl = attachUrl; c.Description = comment; c.UserId = userId; c.When = new DateEpoch(DateTime.UtcNow); List <Comment> cMts = new List <Comment>(); if (issue?.Comments?.Length > 0) { cMts.AddRange(issue.Comments); cMts.Add(c); oDoc.SetPropertyValue(cStrComments, cMts.ToArray()); } else { cMts.Add(c); oDoc.SetPropertyValue(cStrComments, cMts.ToArray()); } var updated = await client.ReplaceDocumentAsync(oDoc); issue = (IncidentInfo)(dynamic)updated.Resource; } return(issue); } else { return(null); } }
public async Task <IncidentInfo> ChangePropertyValue(string id, string propValue, string propName) { if (client == null) { Connect2DocDb(); } if (info != null && client != null) { var cases = from c in client.CreateDocumentQuery(docDbUrl) where c.Id.ToUpper().Contains(id.ToUpper()) select c; IncidentInfo issue = null; Document oDoc = null; foreach (var cs in cases) { var it = await client.ReadDocumentAsync(cs.AltLink); oDoc = it; issue = (IncidentInfo)(dynamic)it.Resource; break; } if (oDoc != null) { switch (propName) { case cStrSeverityProp: oDoc.SetPropertyValue(cStrSeverityProp, propValue); break; case cStrStatusProp: oDoc.SetPropertyValue(cStrStatusProp, propValue); break; case cStrFrequencyProp: oDoc.SetPropertyValue(cStrFrequencyProp, propValue); break; case cStrCTProp: oDoc.SetPropertyValue(cStrCTProp, propValue); break; case cStrClosedProp: oDoc.SetPropertyValue(cStrClosedProp, issue.Closed); break; } var updated = await client.ReplaceDocumentAsync(oDoc); issue = (IncidentInfo)(dynamic)updated.Resource; } return(issue); } else { return(null); } }
public async Task <IncidentInfo> AddResource(string id, IncidentStatus stage, string engineer, DateTime st, DateTime end) { if (client == null) { Connect2DocDb(); } if (info != null && client != null) { var cases = from c in client.CreateDocumentQuery(docDbUrl) where c.Id.ToUpper().Contains(id.ToUpper()) select c; IncidentInfo issue = null; Document oDoc = null; foreach (var cs in cases) { var it = await client.ReadDocumentAsync(cs.AltLink); oDoc = it; issue = (IncidentInfo)(dynamic)it.Resource; break; } if (oDoc != null) { AllocatedResource rc = new AllocatedResource(); rc.End = new DateEpoch((end != null) ? end.ToUniversalTime() : DateTime.UtcNow); rc.Engineer = engineer; rc.Stage = EnumUtils.stringValueOf(stage); rc.Start = new DateEpoch((st != null) ? st.ToUniversalTime() : DateTime.UtcNow); List <AllocatedResource> rRsc = new List <AllocatedResource>(); if (issue?.Resources?.Length > 0) { rRsc.AddRange(issue.Resources); rRsc.Add(rc); oDoc.SetPropertyValue(cStrResources, rRsc.ToArray()); } else { rRsc.Add(rc); oDoc.SetPropertyValue(cStrResources, rRsc.ToArray()); } var updated = await client.ReplaceDocumentAsync(oDoc); issue = (IncidentInfo)(dynamic)updated.Resource; } return(issue); } else { return(null); } }