protected String SetNotificationStatus(NotificationSAP notification) { String status; if (notification.CompletedDate != nullDate) { status = "Completed"; } else { if (notification.EstEndDate < System.DateTime.Today && notification.EstEndDate != nullDate) { status = "Late"; } if (notification.EstEndDate == nullDate) { status = "Not Started"; } else { status = "In Progress"; } } return(status); }
protected void VerifyIfNotificationPartnerAsBeenModified(NotificationSAP notification) { Notification n = (from p in _context.Notification where p.NotificationSapId == TrimZerosFromSAPId(notification.NotificationSapId) select p).FirstOrDefault(); Dictionary <string, NotificationPartner> partners = (from p in _context.NotificationPartner where p.NotificationId == n.Id select p).ToDictionary(p => p.ConcatenatedId, p => p); var listOfPartnerTobeDeleted = (from p in _context.NotificationPartner where p.NotificationId == n.Id select p).ToDictionary(p => p.ConcatenatedId, p => p); List <Partner> listOfPartnerTobeAdded = new List <Partner>(); foreach (var partner in notification.Partners) { int employeeId = (from p in _context.Employe where p.IdSAP == TrimZerosFromSAPId(partner.EmployeId) select p.Id).FirstOrDefault(); int roleId = (from p in _context.Role where p.RoleSigle == partner.Role select p.Id).FirstOrDefault(); string concatenatedId = CreatePartnerConcatenatedId(n.NotificationSapId, employeeId, roleId); if (partners.ContainsKey(concatenatedId)) { listOfPartnerTobeDeleted.Remove(concatenatedId); } else { listOfPartnerTobeAdded.Add(partner); } } if (listOfPartnerTobeDeleted.Any()) { foreach (NotificationPartner partner in listOfPartnerTobeDeleted.Values) { _context.NotificationPartner.Remove(partner); } } if (listOfPartnerTobeAdded.Any()) { foreach (Partner partner in listOfPartnerTobeAdded) { try { _context.NotificationPartner.Add(CreatePartnerWithExistingNotification(partner, notification)); } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } } } }
protected Notification CreateNotification(NotificationSAP notification) { Notification notificationEntity = new Notification(); string projectSAPId = RemoveUnusedDigitFromSAPProjectId(notification.ProjectId); if (VerifyIfNotificationHasValideProjectAffiliated(projectSAPId)) { notificationEntity.ProjectId = (from p in _context.Project where p.ProjectSapId == projectSAPId select p.Id).FirstOrDefault(); notificationEntity.NotificationSapId = TrimZerosFromSAPId(notification.NotificationSapId); notificationEntity.Description = notification.Description; notificationEntity.CreationDate = notification.CreationDate; notificationEntity.StartDate = notification.StartDate; notificationEntity.EstEndDate = notification.EstEndDate; notificationEntity.Status = SetNotificationStatus(notification); notificationEntity.Department = notification.Department; notificationEntity.Priority = notification.Priority; notificationEntity.EstEffort = string.IsNullOrEmpty(notification.EstEffort) ? 0 : Convert.ToInt32(notification.EstEffort); notificationEntity.ActualEffort = string.IsNullOrEmpty(notification.ActualEffort) ? 0 : Convert.ToInt32(notification.ActualEffort); notificationEntity.IsCompleted = SetNotificationIsCompleted(notification); notificationEntity.CompletedDate = notification.CompletedDate; return(notificationEntity); } else { throw new System.ArgumentException("A notification needs to be affilated to a projectID", "original"); } }
protected bool SetNotificationIsCompleted(NotificationSAP notification) { if (notification.IsCompleted == "True") { return(true); } else { return(false); } }
protected NotificationPartner CreatePartnerWithExistingNotification(Partner partner, NotificationSAP notification) { NotificationPartner partnerEntity = new NotificationPartner(); Notification n = (from p in _context.Notification where p.NotificationSapId == TrimZerosFromSAPId(notification.NotificationSapId) select p).FirstOrDefault(); partnerEntity.NotificationId = n.Id; string employeeSAPId = TrimZerosFromSAPId(partner.EmployeId); int employeeId = (from p in _context.Employe where p.IdSAP == employeeSAPId select p.Id).FirstOrDefault(); if (employeeId != 0) { partnerEntity.EmployeId = employeeId; } else { throw new System.ArgumentException("A partner needs an employeeId to be valid"); } var roleId = (from p in _context.Role where p.RoleSigle == partner.Role select p.Id).FirstOrDefault(); if (roleId != 0) { partnerEntity.RoleId = roleId; } else { throw new System.ArgumentException("A partner needs a role to be valid"); } partnerEntity.ConcatenatedId = CreatePartnerConcatenatedId(n.NotificationSapId, employeeId, roleId); return(partnerEntity); }