public override DTO.CushionColorMng.EditFormData GetData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.CushionColorMng.EditFormData data = new DTO.CushionColorMng.EditFormData(); data.Data = new DTO.CushionColorMng.CushionColor(); data.Data.CushionColorProductGroups = new List <DTO.CushionColorMng.CushionColorProductGroup>(); data.Data.CushionColorTestReports = new List <DTO.CushionColorMng.CushionColorTestReport>(); data.Seasons = new List <DTO.Support.Season>(); data.CushionTypes = new List <DTO.Support.CushionType>(); data.Data.CushionTestingDTOs = new List <DTO.CushionColorMng.CushionTestingDTO>(); //try to get data try { using (CushionColorMngEntities context = CreateContext()) { if (id == 0) { data.Data.ImageFile_DisplayUrl = FrameworkSetting.Setting.ThumbnailUrl + "no-image.jpg"; int index = -1; foreach (DTO.Support.ProductGroup dtoGroup in supportFactory.GetProductGroup()) { data.Data.CushionColorProductGroups.Add(new DTO.CushionColorMng.CushionColorProductGroup() { CushionColorProductGroupID = index, ProductGroupID = dtoGroup.ProductGroupID, ProductGroupNM = dtoGroup.ProductGroupNM, IsEnabled = false }); index--; } } else { data.Data = converter.DB2DTO_CushionColor(context.CushionColorMng_CushionColor_View.Include("CushionColorMng_CushionColorProductGroup_View").FirstOrDefault(o => o.CushionColorID == id)); } data.Seasons = supportFactory.GetSeason().ToList(); data.CushionTypes = supportFactory.GetCushionType().ToList(); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
private void SendToEmailNotification(CushionColorMngEntities context, string emailSubject, string emailBody) { try { string sendToEmail = string.Empty; // My(AVT)[20] and Thanh(AVT)[74] foreach (var empObj in context.EmployeeMng_Employee_View.Where(o => !string.IsNullOrEmpty(o.Email1) && (o.UserID == 20 || o.UserID == 74 || o.UserID == 1)).ToList()) { if (!string.IsNullOrEmpty(sendToEmail)) { sendToEmail += "; "; } sendToEmail += empObj.Email1; // add to NotificationMessage table context.NotificationMessage.Add(new NotificationMessage { UserID = empObj.UserID, NotificationMessageTag = Module.Framework.ConstantIdentifier.MOBILE_APP_MESSAGE_TAG_PRODUCTION, NotificationMessageTitle = emailSubject, NotificationMessageContent = emailBody }); } // Create data EmailNotificationMessage. EmailNotificationMessage emailNotificationMessage = new EmailNotificationMessage(); emailNotificationMessage.EmailSubject = emailSubject; emailNotificationMessage.EmailBody = emailBody; emailNotificationMessage.SendTo = sendToEmail; context.EmailNotificationMessage.Add(emailNotificationMessage); context.SaveChanges(); } catch { throw; } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (CushionColorMngEntities context = CreateContext()) { CushionColor dbItem = context.CushionColor.FirstOrDefault(o => o.CushionColorID == id); if (dbItem == null) { notification.Message = "CushionColor not found!"; return(false); } else { var item = context.CushionColorMng_CushionColorCheck_View.Where(o => o.CushionColorID == id).FirstOrDefault(); //CheckPermission if (item.isUsed.Value == true) { throw new Exception("You can't delete because it used in item other!"); } context.CushionColor.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override DTO.CushionColorMng.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.CushionColorMng.SearchFormData data = new DTO.CushionColorMng.SearchFormData(); data.Data = new List <DTO.CushionColorMng.CushionColorSearchResult>(); totalRows = 0; string CushionColorUD = null; string CushionColorNM = null; string Season = null; bool? IsStandard = null; bool? IsEnabled = null; int? ProductGroupID = null; int? CushionTypeID = null; if (filters.ContainsKey("CushionColorUD") && !string.IsNullOrEmpty(filters["CushionColorUD"].ToString())) { CushionColorUD = filters["CushionColorUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("CushionColorNM") && !string.IsNullOrEmpty(filters["CushionColorNM"].ToString())) { CushionColorNM = filters["CushionColorNM"].ToString().Replace("'", "''"); } if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString())) { Season = filters["Season"].ToString().Replace("'", "''"); } if (filters.ContainsKey("IsStandard") && filters["IsStandard"] != null && !string.IsNullOrEmpty(filters["IsStandard"].ToString())) { IsStandard = (filters["IsStandard"].ToString() == "true") ? true : false; } if (filters.ContainsKey("IsEnabled") && filters["IsEnabled"] != null && !string.IsNullOrEmpty(filters["IsEnabled"].ToString())) { IsEnabled = (filters["IsEnabled"].ToString() == "true") ? true : false; } if (filters.ContainsKey("ProductGroupID") && filters["ProductGroupID"] != null && !string.IsNullOrEmpty(filters["ProductGroupID"].ToString())) { ProductGroupID = Convert.ToInt32(filters["ProductGroupID"]); } if (filters.ContainsKey("CushionTypeID") && filters["CushionTypeID"] != null && !string.IsNullOrEmpty(filters["CushionTypeID"].ToString())) { CushionTypeID = Convert.ToInt32(filters["CushionTypeID"]); } //try to get data try { using (CushionColorMngEntities context = CreateContext()) { totalRows = context.CushionColorMng_function_SearchCushionColor(CushionColorUD, CushionColorNM, Season, IsStandard, IsEnabled, ProductGroupID, CushionTypeID, orderBy, orderDirection).Count(); var result = context.CushionColorMng_function_SearchCushionColor(CushionColorUD, CushionColorNM, Season, IsStandard, IsEnabled, ProductGroupID, CushionTypeID, orderBy, orderDirection); data.Data = converter.DB2DTO_CushionColorSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }