示例#1
0
        public override DTO.EditFormData GetData(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.MaterialTypes();

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

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

            string MaterialTypeUD = null;
            string MaterialTypeNM = null;

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

            //try to get data
            try
            {
                using (MaterialTypeMngEntities context = CreateContext())
                {
                    totalRows = context.MaterialTypeMng_function_SearchMaterialType(MaterialTypeUD, MaterialTypeNM, orderBy, orderDirection).Count();
                    var result = context.MaterialTypeMng_function_SearchMaterialType(MaterialTypeUD, MaterialTypeNM, orderBy, orderDirection);
                    data.Data = converter.DB2DTO_MaterialTypeSearchResultList(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 override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (MaterialTypeMngEntities context = CreateContext())
                {
                    MaterialType dbItem = context.MaterialType.FirstOrDefault(o => o.MaterialTypeID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Material Type not found!";
                        return(false);
                    }
                    else
                    {
                        var item = context.MaterialTypeMng_MaterialTypeCheck_View.Where(o => o.MaterialTypeID == id).FirstOrDefault();
                        //CheckPermission
                        if (item.isUsed.Value == true)
                        {
                            throw new Exception("You can't delete because it used in item other!");
                        }
                        context.MaterialType.Remove(dbItem);
                        context.SaveChanges();

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

                return(false);
            }
        }