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); }
protected ProjectNetflixContributor CreateNetflixProjectContributor(NotificationPartner partner) { int totalEffort = 0; var potentielDaysOfWork = 0; DateTime latestDate = DateTime.Today; DateTime StartDate = DateTime.Today; var employee = (from p in _context.Employe where p.Id == partner.EmployeId select p).First(); //var tasks = (from p in _context.TaskOwner // join t in _context.Task on p.TaskId equals t.Id // where p.EmployeId == partner.EmployeId // select new { taskOwner = p, task = t }).ToList(); //foreach (var task in tasks) //{ // if (task.task.Status != "Completed") // { // totalEffort = totalEffort + task.task.EstEffort; // if (latestDate < task.task.EstEnd) // { // latestDate = task.task.EstEnd; // } // } //} //while (StartDate <= latestDate) //{ // if (StartDate.DayOfWeek != DayOfWeek.Saturday && StartDate.DayOfWeek != DayOfWeek.Sunday) // { // ++potentielDaysOfWork; // } // StartDate = StartDate.AddDays(1); //} //var availableTimeForProjects = potentielDaysOfWork * (employee.Workload / 5) * employee.ProjectWorkRatio / 100; //var occupancyRate = totalEffort / availableTimeForProjects * 100; ProjectNetflixContributor contributor_netflix = new ProjectNetflixContributor() { Id = partner.Id, Department = employee.Department, Name = employee.Name, EmployeeId = employee.IdSAP, Picture = employee.Picture, Title = employee.Title, OccupancyRate = 0 }; return(contributor_netflix); }
public void RefreshNotifications() { IEnumerable <NotificationSAP> notifications = new List <NotificationSAP>(); notifications = GetNotificationsSAP().Result; List <String> ExistingNotificationsInDatabase = new List <String>(); ExistingNotificationsInDatabase = (from p in _context.Notification select p.NotificationSapId).ToList(); foreach (NotificationSAP notification in notifications) { Notification notificationEntitity = new Notification(); try { notificationEntitity = CreateNotification(notification); } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } if (!VerifyIfNotificationAlreadyExistsInDataBase(notificationEntitity)) { _context.Notification.Add(notificationEntitity); if (notification.Partners.Any()) { foreach (Partner partner in notification.Partners) { try { NotificationPartner partnerEntity = CreatePartner(partner, notificationEntitity); _context.NotificationPartner.Add(partnerEntity); } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } } } } else { if (VerifyIfNotificationAsBeenModified(notificationEntitity)) { updateNotificationInDatabase(notificationEntitity); } VerifyIfNotificationPartnerAsBeenModified(notification); } ExistingNotificationsInDatabase.Remove(notificationEntitity.NotificationSapId); if (notification.Tasks.Any()) { updateNotificationTasks(notification.Tasks, notificationEntitity); } } deleteUnexistingNotificationInSAP(ExistingNotificationsInDatabase); _context.SaveChanges(); }