Exemplo n.º 1
0
        public override DTO.SubMaterialColorMng.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SubMaterialColorMng.EditFormData data = new DTO.SubMaterialColorMng.EditFormData();
            data.Data = new DTO.SubMaterialColorMng.SubMaterialColor();

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

            return(data);
        }
Exemplo n.º 2
0
        public override DTO.SubMaterialColorMng.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.SubMaterialColorMng.SearchFormData data = new DTO.SubMaterialColorMng.SearchFormData();
            data.Data = new List <DTO.SubMaterialColorMng.SubMaterialColorSearchResult>();
            totalRows = 0;

            string SubMaterialColorUD = null;
            string SubMaterialColorNM = null;

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

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

            return(data);
        }
Exemplo n.º 3
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            try
            {
                using (SubMaterialColorMngEntities context = CreateContext())
                {
                    SubMaterialColor dbItem = context.SubMaterialColor.FirstOrDefault(o => o.SubMaterialColorID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sub material not found!";
                        return(false);
                    }
                    else
                    {
                        var item = context.SubMaterialColorMng_SubMaterialColorCheck_View.Where(o => o.SubMaterialColorID == id).FirstOrDefault();
                        //CheckPermission
                        if (item.isUsed.Value == true)
                        {
                            throw new Exception("You can't delete because it used in item other!");
                        }
                        context.SubMaterialColor.Remove(dbItem);
                        context.SaveChanges();

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