Ejemplo n.º 1
0
        public async Task <IActionResult> GetAlarmEmailNotificationByStatus(int csId, int ssId, int lId, int statusId)
        {
            CurrentUser cUser = new CurrentUser(HttpContext, _configuration);

            try
            {
                /* The last parameter is "Mode" which is used to return Dynamic or Specific object Result */
                var result = await AlarmEmailNotificationRepo.GetAlarmEmailNotificationByStatus(csId, ssId, lId, statusId, null);

                await auditLogService.LogActivity(cUser.UserId, cUser.HostIP, cUser.SessionId, "AlarmEmailNotification", "AlarmEmailNotification list Loaded.");

                return(Ok(result));
            }
            catch (CustomException cex)
            {
                var responseObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, responseObj));
            }
            catch (Exception ex)
            {
                return(Ok(new EmaintenanceMessage(ex.Message)));
            }
        }
        public async Task <IActionResult> GenerateJobs(int csId, int ssId)
        {
            try
            {
                CurrentUser cUser = new CurrentUser(HttpContext, _configuration);

                var sems = (List <AlarmEmailNotificationEntityModel>) await alarmEmailNotificationRepo.GetAlarmEmailNotificationByStatus(csId, ssId, 0, 0, "GenerateJob");

                var equipments = (List <AlarmEmailNotificationEntityModel>) await alarmEmailNotificationRepo.GetEquipmentByAlarmEmailNotificationId(csId, ssId, 0, "GenerateJob");

                if (sems != null && sems.Count > 0)
                {
                    var sem = sems[0];
                    List <JobServicesViewModel>   jsvms = null;
                    List <JobEquipmentsViewModel> jevms = null;

                    /** Deserializing the Schedule Equipement Object and Looping into Job Service Object */
                    List <AlarmEmailNotificationEquipmentsViewModel> sevms = JsonConvert.DeserializeObject <List <AlarmEmailNotificationEquipmentsViewModel> >(equipments[0].AlarmEmailNotificationEquipments);
                    if (sevms != null && sevms.Count > 0)
                    {
                        jevms = new List <JobEquipmentsViewModel>();
                        foreach (AlarmEmailNotificationEquipmentsViewModel sevm in sevms)
                        {
                            if (sevm.Active == "Y")
                            {
                                JobEquipmentsViewModel jsvm = new JobEquipmentsViewModel
                                {
                                    JobEquipmentId = 0,
                                    EquipmentId    = sevm.EquipmentId,
                                };
                                jevms.Add(jsvm);
                            }
                        }
                    }

                    foreach (DateTime StartDate in DateUtils.GetDatesBetweenRange(sem.StartDate, sem.EndDate, sem.IntervalDays))
                    {
                        //AlarmEmailNotificationEquipmentsViewModel jvm = new AlarmEmailNotificationEquipmentsViewModel
                        //{
                        //    JobId = 0,
                        //    AlarmEmailNotificationSetupId = sem.AlarmEmailNotificationSetupId,
                        //    JobName = sem.AlarmEmailNotificationName,
                        //    ClientSiteId = csId,
                        //    EstStartDate = StartDate,
                        //    EstEndDate = StartDate.AddDays(sem.EstJobDays - 1),
                        //    JobServices = jsvms,
                        //    JobEquipments = jevms,
                        //    UserId = cUser.UserId
                        //};
                        //await EmailConfigurationRepo.SaveOrUpdate(jvm);
                    }
                }
                await auditLogService.LogActivity(cUser.UserId, cUser.HostIP, cUser.SessionId, "Jobs", "Job Generated.");

                return(Ok());
            }
            catch (CustomException cex)
            {
                var responseObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, responseObj));
            }
            catch (Exception ex)
            {
                return(Ok(new EmaintenanceMessage(ex.Message)));
            }
        }