private List <InboxDocumentModel> GetDocumentsByInbox(List <InboxItem> inbox) { var ids = inbox.Select(x => x.ProcessId).Distinct().ToList(); var documents = _documentRepository.GetByIds(ids) .ToDictionary(x => x.Id, x => x); var docs = new List <InboxDocumentModel>(); foreach (var inboxItem in inbox) { InboxDocumentModel doc; //if document is exists if (documents.TryGetValue(inboxItem.ProcessId, out Document _doc)) { doc = GetDocumentModel <InboxDocumentModel>(_doc); } else { doc = new InboxDocumentModel(); doc.Id = inboxItem.ProcessId; doc.IsCorrect = false; doc.StateName = DocumentModel.NotFoundError; } doc.AvailableCommands = inboxItem.AvailableCommands; doc.AddingDate = inboxItem.AddingDate.ToString(); docs.Add(doc); } return(docs); }
private InboxDocumentModel ToModel(InboxDocument model) { var result = new InboxDocumentModel(); result.Annotations = model.Annotations; result.AssignedByLogin = model.AssignedByLogin; result.AssignedByName = model.AssignedByName; result.AssignedToCCControl = model.AssignedToCCControl; result.AssignedToCCLogin = model.AssignedToCCLogin; result.AssignedToCCName = model.AssignedToCCName; result.AssignedToControl = model.AssignedToControl; result.AssignedToLogin = model.AssignedToLogin; result.AssignedToName = model.AssignedToName; result.AssignmentDate = model.AssignmentDate.HasValue ? model.AssignmentDate.Value:DateTime.MinValue; result.Attachment1Url = model.AttachmentUrl; result.CompanyName = model.CompanyName; result.DepartmentName = model.DepartmentName; result.DocumentCode = model.DocumentCode; result.DocumentDate = model.DocumentDate.HasValue ? model.DocumentDate.Value : DateTime.MinValue; result.DocumentStatus = model.DocumentStatus; result.DocumentSubject = model.DocumentSubject; result.FirstReminderDate = model.FirstReminderDate.HasValue ? model.FirstReminderDate.Value : DateTime.MinValue; result.FromCompany = model.FromCompany; result.FromContact = model.FromContact; result.IncomingMailboxId = model.IncomingMailboxId; result.ResponseDate = model.ResponseDate.HasValue ? model.ResponseDate.Value : DateTime.MinValue; result.SecondReminderDate = model.SecondReminderDate.HasValue ? model.SecondReminderDate.Value : DateTime.MinValue; result.SiteUrl = model.SiteUrl; return(result); }
public InboxDocumentModel GetIncomingDocument(int docId) { var tmp = context.InboxDocument.FirstOrDefault(x => x.IncomingMailboxId == docId); var result = new InboxDocumentModel(); if (tmp != null) { result = ToModel(tmp); } return(result); }
public int SaveInboxDocument(InboxDocumentModel model) { var result = 0; var tmp = ToEntity(model); var tmpDetail = new InboxDocumentDetail(); tmpDetail.AssignedByLogin = model.AssignedByLogin; tmpDetail.AssignedByName = model.AssignedByName; tmpDetail.AssignedToLogin = model.AssignedToLogin; tmpDetail.AssignedToName = model.AssignedToName; tmpDetail.AssignedToCCLogin = model.AssignedToCCLogin; tmpDetail.AssignedToCCName = model.AssignedToCCName; tmpDetail.AssignmentDate = model.AssignmentDate; tmpDetail.AssignmentStatus = model.DocumentStatus; tmpDetail.DocumentAnnotation = model.Annotations; tmpDetail.AssignmentDueTo = model.ResponseDate; if (model.IncomingMailboxId > 0) { tmp = context.InboxDocument.FirstOrDefault(x => x.IncomingMailboxId == model.IncomingMailboxId); if (model.DocumentStatus == "Asignado") { tmp.AssignedByLogin = model.AssignedByLogin; tmp.AssignedByName = model.AssignedByName; tmp.AssignedToCCControl = model.AssignedToCCControl; tmp.AssignedToCCLogin = model.AssignedToCCLogin; tmp.AssignedToCCName = model.AssignedToCCName; tmp.AssignedToControl = model.AssignedToControl; tmp.AssignedToLogin = model.AssignedToLogin; tmp.AssignedToName = model.AssignedToName; tmp.AssignmentDate = model.AssignmentDate; tmp.ResponseDate = model.ResponseDate; tmp.FirstReminderDate = model.FirstReminderDate; tmp.SecondReminderDate = model.SecondReminderDate; } tmp.Annotations = model.Annotations; tmp.DocumentStatus = model.DocumentStatus; } else { context.InboxDocument.Add(tmp); } context.SaveChanges(); tmpDetail.IncomingDocumentId = tmp.IncomingMailboxId; context.InboxDocumentDetail.Add(tmpDetail); context.SaveChanges(); result = tmp.IncomingMailboxId; return(result); }
//public IHttpActionResult PostInMailbox(MailboxDocumentModel document) //{ // var result = new PostEntityModelResponse(); // try // { // result.ItemId = helper.SaveIncomingMailbox(document); // if (result.ItemId <= 0) // result.Message = "No records were saved."; // } // catch (Exception ex) // { // result.Message = "An error occured while saving your information."; // } // return Ok(result); //} public IHttpActionResult PostInMailbox(InboxDocumentModel document) { var result = new PostEntityModelResponse(); try { result.ItemId = helper.SaveInboxDocument(document); if (result.ItemId <= 0) { result.Message = "No records were saved."; } } catch (Exception ex) { result.Message = "An error occured while saving your information."; } return(Ok(result)); }
public async Task <string> PostInMailbox(InboxDocumentModel document, string temp) { var result = 0; string actionEndpoint = "inmailbox/InMailbox"; PostEntityModelResponse serviceResult = new PostEntityModelResponse(); using (var client = new HttpClient()) { using (var request = new HttpRequestMessage(HttpMethod.Get, baseEndpoint + actionEndpoint)) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); using (HttpResponseMessage response = await client.PostAsJsonAsync(request.RequestUri, document)) { if (response.StatusCode == HttpStatusCode.OK) { serviceResult = JsonConvert.DeserializeObject <PostEntityModelResponse>(response.Content.ReadAsStringAsync().Result); result = serviceResult.ItemId; } } } } return(JsonConvert.SerializeObject(result)); }
public async Task <string> GetInMailbox(int documentId) { string actionEndpoint = "inmailbox/IncomingMailbox"; string queryParameter = string.Format("?docId={0}", documentId); GetIncomingMailboxResponse serviceResult = new GetIncomingMailboxResponse(); InboxDocumentModel result = new InboxDocumentModel(); using (var client = new HttpClient()) { using (var request = new HttpRequestMessage(HttpMethod.Get, baseEndpoint + actionEndpoint + queryParameter)) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); using (HttpResponseMessage response = await client.SendAsync(request)) { if (response.StatusCode == HttpStatusCode.OK) { serviceResult = JsonConvert.DeserializeObject <GetIncomingMailboxResponse>(response.Content.ReadAsStringAsync().Result); result = serviceResult.Model; } } } } return(JsonConvert.SerializeObject(result)); }
public NewInboxViewModel() { DBModel = new InboxDocumentModel(); }