public override EditFormData GetData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; EditFormData data = new EditFormData(); data.Data = new FrameMaterialColorDTO(); //try to get data try { if (id > 0) { using (FrameMaterialColorMngEntities context = CreateContext()) { data.Data = converter.DB2DTO_FrameMaterialColor(context.FrameMaterialColorMng_FrameMaterialColor_View.FirstOrDefault(o => o.FrameMaterialColorID == id)); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
public override 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 }; SearchFormData data = new SearchFormData(); data.Data = new List <FrameMaterialColorSearchResult>(); totalRows = 0; string FrameMaterialColorUD = null; string FrameMaterialColorNM = null; if (filters.ContainsKey("FrameMaterialColorUD") && !string.IsNullOrEmpty(filters["FrameMaterialColorUD"].ToString())) { FrameMaterialColorUD = filters["FrameMaterialColorUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("FrameMaterialColorNM") && !string.IsNullOrEmpty(filters["FrameMaterialColorNM"].ToString())) { FrameMaterialColorNM = filters["FrameMaterialColorNM"].ToString().Replace("'", "''"); } //try to get data try { using (FrameMaterialColorMngEntities context = CreateContext()) { totalRows = context.FrameMaterialColorMng_function_SearchFrameMaterialColor(FrameMaterialColorUD, FrameMaterialColorNM, orderBy, orderDirection).Count(); var result = context.FrameMaterialColorMng_function_SearchFrameMaterialColor(FrameMaterialColorUD, FrameMaterialColorNM, orderBy, orderDirection); data.Data = converter.DB2DTO_FrameMaterialColorSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FrameMaterialColorMngEntities context = CreateContext()) { FrameMaterialColor dbItem = context.FrameMaterialColor.FirstOrDefault(o => o.FrameMaterialColorID == id); if (dbItem == null) { notification.Message = "Frame material color not found!"; return(false); } else { var item = context.FrameMaterialColorMng_FrameMaterialColorCheck_View.Where(o => o.FrameMaterialColorID == id).FirstOrDefault(); //CheckPermission if (item.isUsed.Value == true) { throw new Exception("You can't delete because it used in item other!"); } context.FrameMaterialColor.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }