示例#1
0
        public DTO.EditFormData GetEditData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data = new DTO.MaterialColorData();

            //try to get data
            try
            {
                if (id > 0)
                {
                    using (MaterialColorMngEntities context = CreateContext())
                    {
                        data.Data = converter.DB2DTO_MaterialColor(context.MaterialColorMng_MaterialColor_View.FirstOrDefault(o => o.MaterialColorID == id));
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
示例#2
0
        public DTO.SearchFormData GetDataWithFilters(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.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <DTO.MaterialColorSearchResultData>();
            totalRows = 0;

            string MaterialColorUD = null;
            string MaterialColorNM = null;

            if (filters.ContainsKey("MaterialColorUD") && !string.IsNullOrEmpty(filters["MaterialColorUD"].ToString()))
            {
                MaterialColorUD = filters["MaterialColorUD"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("MaterialColorNM") && !string.IsNullOrEmpty(filters["MaterialColorNM"].ToString()))
            {
                MaterialColorNM = filters["MaterialColorNM"].ToString().Replace("'", "''");
            }

            //try to get data
            try
            {
                using (MaterialColorMngEntities context = CreateContext())
                {
                    totalRows = context.MaterialColorMng_function_SearchMaterialColor(MaterialColorUD, MaterialColorNM, orderBy, orderDirection).Count();
                    var result = context.MaterialColorMng_function_SearchMaterialColor(MaterialColorUD, MaterialColorNM, orderBy, orderDirection);
                    data.Data = converter.DB2DTO_MaterialColorSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
示例#3
0
        public bool Delete(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (MaterialColorMngEntities context = CreateContext())
                {
                    MaterialColor dbItem = context.MaterialColor.FirstOrDefault(o => o.MaterialColorID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "MaterialColor not found!";
                        return(false);
                    }
                    else
                    {
                        var item = context.MaterialColorMng_MaterialColorCheck_View.Where(o => o.MaterialColorID == id).FirstOrDefault();
                        //CheckPermission
                        if (item.isUsed.Value == true)
                        {
                            throw new Exception("You can't delete because it used in item other!");
                        }
                        context.MaterialColor.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }