public ListModuleStatusDTO GetModuleStatuses(int moduleID, int notificationGroupID, out Notification notification) { notification = new Notification() { Type = NotificationType.Success }; ListModuleStatusDTO data = new ListModuleStatusDTO(); data.ModuleStatusDTOs = new List <ModuleStatusDTO>(); data.NotificationGroupStatusDTOs = new List <NotificationGroupStatusDTO>(); try { using (var context = CreateContext()) { var dbItem = context.NotificationMng_ModuleStatus_View.Where(o => o.ModuleID == moduleID); data.ModuleStatusDTOs = converter.DB2DTO_ModuleStatus(dbItem.ToList()); if (notificationGroupID > 0) { data.NotificationGroupStatusDTOs = AutoMapper.Mapper.Map <List <NotificationMng_NotificationGroupStatus_View>, List <NotificationGroupStatusDTO> >(context.NotificationMng_NotificationGroupStatus_View.Where(o => o.ModuleID == moduleID && o.NotificationGroupID == notificationGroupID).ToList()); } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(data); }
public ListModuleStatusDTO UpdateModuleStatus(int id, int moduleID, string statusUD, string statusNM, out Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; ListModuleStatusDTO data = new ListModuleStatusDTO(); if (statusUD == "" || statusUD == null || statusUD == "undefined") { notification.Type = NotificationType.Error; notification.Message = "Please fill code status!"; return(data); } if (statusNM == "" || statusNM == null || statusNM == "undefined") { notification.Type = NotificationType.Error; notification.Message = "Please fill name status!"; return(data); } if (moduleID == null) { notification.Type = NotificationType.Error; notification.Message = "Please choose module!"; return(data); } try { using (var context = CreateContext()) { ModuleStatus dbItem = null; int?listItem = context.ModuleStatus.Where(s => s.ModuleID == moduleID).Max(s => s.StatusID); dbItem = context.ModuleStatus.Where(s => s.ModuleID == moduleID && s.StatusUD == statusUD && s.StatusNM == statusNM).FirstOrDefault(); if (dbItem != null) { notification.Type = NotificationType.Error; notification.Message = "This module is existed " + dbItem.StatusNM; return(data); } dbItem = new ModuleStatus(); context.ModuleStatus.Add(dbItem); ModuleStatusDTO dtoItem = new ModuleStatusDTO(); if (listItem == null) { dtoItem.StatusID = 1; } else { dtoItem.StatusID = listItem + 1; } dtoItem.ModuleStatusID = -1; dtoItem.ModuleID = moduleID; dtoItem.StatusUD = statusUD; dtoItem.StatusNM = statusNM; AutoMapper.Mapper.Map <DTO.ModuleStatusDTO, ModuleStatus>(dtoItem, dbItem); context.SaveChanges(); return(GetModuleStatuses(id, moduleID, out notification)); } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(data); } }