コード例 #1
0
        public async Task <string> SaveScheduleValidation(InspectionScheduleViewModel data)
        {
            var testInspectionSchedule = new InspectionSchedule
            {
                InspectionScheduleId = data.Id,
                ProcessId            = data.ProcessId,
                StartDate            = data.StartTime,
                Timeslot             = (await _prepareService.GetTimeslots(data.TimeslotId)).FirstOrDefault(),
                RecurrenceRule       = data.RecurrenceRule,
                RecurrenceException  = data.RecurrenceException
            };
            var schedules = (await _prepareService.GetInspectionSchedulesNonFilter()).Where(_ => _.ProcessId == data.ProcessId);

            if (data.Id > 0)
            {
                schedules = schedules.Where(s => s.InspectionScheduleId != data.Id);
            }
            //Check validation if schedule data have same inspection in the same timeslot in the same day + recurrence
            var dataDates = RecurrenceHelper.GetRecurrenceDateTimeCollection(testInspectionSchedule);

            foreach (var schedule in schedules)
            {
                var dates     = RecurrenceHelper.GetRecurrenceDateTimeCollection(schedule);
                var intersect = dataDates.Intersect(dates);
                if (intersect.Any())
                {
                    return("L'horaire pour l'inspection sélectionnée, le créneau horaire et la date existe déjà");
                }
            }
            return(string.Empty);
        }
コード例 #2
0
        public Task UpdateSchedule(InspectionSchedule schedule, InspectionScheduleViewModel scheduleViewModel)
        {
            schedule.ProcessId           = scheduleViewModel.ProcessId;
            schedule.StartDate           = scheduleViewModel.StartTime.Date;
            schedule.TimeslotId          = scheduleViewModel.TimeslotId;
            schedule.RecurrenceRule      = scheduleViewModel.RecurrenceRule;
            schedule.RecurrenceException = scheduleViewModel.RecurrenceException;
            schedule.RecurrenceId        = scheduleViewModel.RecurrenceID;
            schedule.MarkAsModified();

            return(_prepareService.SaveInspectionSchedule(schedule));
        }
コード例 #3
0
        /// <summary>
        /// Get Inspection schedule record by organization id and application id
        /// </summary>
        /// <param name="inspectionScheduleId"></param>
        /// <returns></returns>
        public InspectionSchedule GetInspectionSchedule(int organizationId, int applicationId)
        {
            var inspectionSchedulManager          = this.container.GetInstance <InspectionScheduleManager>();
            var inspectionScheduleList            = inspectionSchedulManager.GetInspectionScheduleByOrganizationID(organizationId);
            InspectionSchedule inspectionSchedule = null;

            if (inspectionScheduleList.Count() > 0)
            {
                inspectionSchedule = inspectionScheduleList.Where(x => x.ApplicationId == applicationId).First();
            }

            return(inspectionSchedule);
        }
コード例 #4
0
        public Task InsertSchedule(InspectionScheduleViewModel scheduleViewModel)
        {
            var schedule = new InspectionSchedule
            {
                ProcessId           = scheduleViewModel.ProcessId,
                StartDate           = scheduleViewModel.StartTime.Date,
                TimeslotId          = scheduleViewModel.TimeslotId,
                RecurrenceRule      = scheduleViewModel.RecurrenceRule,
                RecurrenceException = scheduleViewModel.RecurrenceException,
                RecurrenceId        = scheduleViewModel.RecurrenceID
            };

            schedule.MarkAsAdded();

            return(_prepareService.SaveInspectionSchedule(schedule));
        }
コード例 #5
0
        public static IEnumerable <DateTime> GetRecurrenceDateTimeCollection(InspectionSchedule inspectionSchedule, DateTime?StartDateFilter = null, DateTime?EndDateFilter = null)
        {
            if (inspectionSchedule == null)
            {
                throw new ArgumentNullException(nameof(inspectionSchedule));
            }
            if (inspectionSchedule.Timeslot == null)
            {
                throw new ArgumentNullException($"{nameof(inspectionSchedule)}.{nameof(InspectionSchedule.Timeslot)}");
            }

            var excludeDates = inspectionSchedule.RecurrenceException?.Split(',').Select(_ => DateTime.ParseExact(_.Split('T')[0], "yyyyMMdd", CultureInfo.InvariantCulture)).ToList();
            var inspectionScheduleStartDateTime = new DateTime(inspectionSchedule.StartDate.Year,
                                                               inspectionSchedule.StartDate.Month,
                                                               inspectionSchedule.StartDate.Day,
                                                               inspectionSchedule.Timeslot.StartTime.Hours,
                                                               inspectionSchedule.Timeslot.StartTime.Minutes,
                                                               inspectionSchedule.Timeslot.StartTime.Seconds);

            return(GetRecurrenceDateTimeCollection(inspectionSchedule.RecurrenceRule, inspectionScheduleStartDateTime, StartDateFilter, EndDateFilter, excludeDates));
        }
コード例 #6
0
        /// <summary>
        /// Creates a copy of last archived inspection schedule and save in database
        /// </summary>
        /// <param name="inspectionScheduleId"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public InspectionSchedule CloneInspectionSchedule(int inspectionScheduleId, string email)
        {
            var inspectionScheduleManager       = this.container.GetInstance <InspectionScheduleManager>();
            var inspectionScheduleDetailManager = this.container.GetInstance <InspectionScheduleDetailManager>();
            var inspectionScheduleSiteManager   = this.container.GetInstance <InspectionScheduleSiteManager>();

            var inspectionScheduleOld             = inspectionScheduleManager.GetById(inspectionScheduleId);
            InspectionSchedule inspectionSchedule = new InspectionSchedule();

            inspectionSchedule.ApplicationId  = inspectionScheduleOld.ApplicationId;
            inspectionSchedule.IsActive       = true;
            inspectionSchedule.IsArchive      = false;
            inspectionSchedule.OrganizationId = inspectionScheduleOld.OrganizationId;
            inspectionSchedule.InspectionDate = inspectionScheduleOld.InspectionDate;
            inspectionSchedule.StartDate      = inspectionScheduleOld.StartDate;
            inspectionSchedule.EndDate        = inspectionScheduleOld.EndDate;
            inspectionSchedule.CompletionDate = inspectionScheduleOld.CompletionDate;
            inspectionSchedule.CreatedDate    = DateTime.Now;
            inspectionSchedule.CreatedBy      = email;
            inspectionSchedule.UpdatedDate    = DateTime.Now;
            inspectionSchedule.IsCompleted    = false;

            inspectionScheduleManager.Add(inspectionSchedule);

            var inspectionScheduleDetailListOld = GetActiveByInspectionScheduleId(inspectionScheduleOld.Id);

            foreach (var inspectionScheduleDetailOld in inspectionScheduleOld.InspectionScheduleDetails)
            {
                InspectionScheduleDetail inspectionScheduleDetail = new InspectionScheduleDetail();

                inspectionScheduleDetail.InspectionScheduleId = inspectionSchedule.Id;
                inspectionScheduleDetail.AccreditationRoleId  = inspectionScheduleDetailOld.AccreditationRoleId;
                inspectionScheduleDetail.UserId = inspectionScheduleDetailOld.UserId;
                inspectionScheduleDetail.InspectionCategoryId = inspectionScheduleDetailOld.InspectionCategoryId;
                inspectionScheduleDetail.SiteId      = inspectionScheduleDetailOld.SiteId;
                inspectionScheduleDetail.IsLead      = inspectionScheduleDetailOld.IsLead;
                inspectionScheduleDetail.IsMentor    = inspectionScheduleDetailOld.IsMentor;
                inspectionScheduleDetail.IsActive    = true;
                inspectionScheduleDetail.IsArchive   = false;
                inspectionScheduleDetail.CreatedDate = DateTime.Now;
                inspectionScheduleDetail.CreatedBy   = email;

                inspectionScheduleDetailManager.BatchAdd(inspectionScheduleDetail);
            }

            inspectionScheduleDetailManager.SaveChanges();

            var existingInspectionScheduleSites = inspectionScheduleSiteManager.GetSiteByInspectionScheduleId(inspectionScheduleOld.Id);

            foreach (var site in existingInspectionScheduleSites)
            {
                InspectionScheduleSite inspectionScheduleSite = new InspectionScheduleSite();
                inspectionScheduleSite.SiteID = site.SiteID;
                inspectionScheduleSite.InspectionScheduleId = inspectionSchedule.Id;
                inspectionScheduleSite.InspectionDate       = site.InspectionDate;
                inspectionScheduleSite.CreatedBy            = email;
                inspectionScheduleSite.CreatedDate          = DateTime.Now;

                inspectionScheduleSiteManager.BatchAdd(inspectionScheduleSite);
            }

            inspectionScheduleSiteManager.SaveChanges();

            return(inspectionSchedule);
        }
コード例 #7
0
        /// <summary>
        /// Adds new inspection schedule and inspection schedule details record
        /// </summary>
        /// <param name="inspectionScheduleId"></param>
        /// <param name="inspectionScheduleDetailId"></param>
        /// <param name="organizationId"></param>
        /// <param name="applicationId"></param>
        /// <param name="selectedUserId"></param>
        /// <param name="selectedRoleId"></param>
        /// <param name="selectedCategoryId"></param>
        /// <param name="lead"></param>
        /// <param name="mentor"></param>
        /// <param name="inspDate"></param>
        /// <param name="selectedFacilityList"></param>
        /// <param name="userEmail"></param>
        public int SaveInspectionSchedule(string inspectionScheduleId, string inspectionScheduleDetailId, string organizationId, string applicationId, string selectedUserId, string selectedRoleId, string selectedCategoryId, bool lead, bool mentor, string startDate, string endDate, List <FacilitySiteItems> selectedSitesList, string userEmail, string selectedSiteId)
        {
            var inspectionScheduleManager       = this.container.GetInstance <InspectionScheduleManager>();
            var inspectionScheduleDetailManager = this.container.GetInstance <InspectionScheduleDetailManager>();
            var orgManager       = this.container.GetInstance <OrganizationManager>();
            var userManager      = this.container.GetInstance <UserManager>();
            var trueVaultManager = this.container.GetInstance <TrueVaultManager>();

            var inspectionScheduleIdLocal = 0;

            if (inspectionScheduleId == "0") // New Schedule
            {
                var inspectionSchedule = new InspectionSchedule
                {
                    ApplicationId  = Convert.ToInt32(applicationId),
                    Id             = Convert.ToInt32(inspectionScheduleId),
                    IsActive       = true,
                    IsArchive      = false,
                    OrganizationId = Convert.ToInt32(organizationId),
                    InspectionDate = DateTime.Now,
                    StartDate      = Convert.ToDateTime(startDate),
                    EndDate        = Convert.ToDateTime(endDate),
                    CompletionDate = DateTime.Now,
                    CreatedDate    = DateTime.Now,
                    CreatedBy      = userEmail,
                    UpdatedDate    = DateTime.Now,
                    IsCompleted    = false
                };
                //Convert.ToDateTime(inspDate);

                inspectionScheduleManager.Add(inspectionSchedule);
                inspectionScheduleIdLocal = inspectionSchedule.Id;
            }
            else // Update Schedule
            {
                inspectionScheduleIdLocal = Convert.ToInt32(inspectionScheduleId);
                var inspectionSchedule = inspectionScheduleManager.GetById(inspectionScheduleIdLocal);
                inspectionSchedule.InspectionDate = DateTime.Now;//Convert.ToDateTime(inspDate);
                inspectionSchedule.StartDate      = Convert.ToDateTime(startDate);
                inspectionSchedule.EndDate        = Convert.ToDateTime(endDate);
                inspectionSchedule.UpdatedDate    = DateTime.Now;
                inspectionSchedule.UpdatedBy      = userEmail;
                inspectionScheduleManager.Save(inspectionSchedule);
            }


            if (!string.IsNullOrEmpty(inspectionScheduleDetailId)) // Just Save schedule not schedule detail
            {
                var userId = Guid.Parse(selectedUserId);
                var groups = trueVaultManager.GetAllGroups();

                if (inspectionScheduleDetailId == "0") // new inspection schedule detail
                {
                    var inspectionScheduleDetail = new InspectionScheduleDetail
                    {
                        AccreditationRoleId = Convert.ToInt32(selectedRoleId),
                        UserId = userId,
                        InspectionCategoryId = Convert.ToInt32(selectedCategoryId),
                        InspectionScheduleId = inspectionScheduleIdLocal,
                        SiteId      = Convert.ToInt32(selectedSiteId),
                        IsLead      = lead,
                        IsMentor    = mentor,
                        CreatedDate = DateTime.Now,
                        UpdatedDate = DateTime.Now,
                        CreatedBy   = userEmail,
                        IsActive    = true,
                        IsArchive   = false
                    };

                    inspectionScheduleDetailManager.Add(inspectionScheduleDetail);
                }
                else // edit inspection schedule detail
                {
                    var inspectionScheduleDetail = inspectionScheduleDetailManager.GetById(Convert.ToInt32(inspectionScheduleDetailId));
                    inspectionScheduleDetail.AccreditationRoleId = Convert.ToInt32(selectedRoleId);
                    inspectionScheduleDetail.UserId = userId;
                    inspectionScheduleDetail.InspectionCategoryId = Convert.ToInt32(selectedCategoryId);
                    inspectionScheduleDetail.SiteId      = Convert.ToInt32(selectedSiteId);
                    inspectionScheduleDetail.IsLead      = lead;
                    inspectionScheduleDetail.IsMentor    = mentor;
                    inspectionScheduleDetail.UpdatedDate = DateTime.Now;
                    inspectionScheduleDetail.UpdatedBy   = userEmail;
                    inspectionScheduleDetailManager.Save(inspectionScheduleDetail);
                }

                var user = userManager.GetById(userId);
                var org  = orgManager.GetById(Convert.ToInt32(organizationId));

                var userOrgs = new List <UserOrganizationItem>
                {
                    new UserOrganizationItem
                    {
                        Organization = new OrganizationItem
                        {
                            OrganizationName       = org.Name,
                            DocumentLibraryGroupId = org.DocumentLibraryGroupId
                        }
                    }
                };

                trueVaultManager.AddUserToGroups(userOrgs, user.DocumentLibraryUserId, groups);
            }

            UpdateInspectionScheduleSite(selectedSitesList, inspectionScheduleIdLocal, userEmail);

            return(inspectionScheduleIdLocal);
        }