Exemple #1
0
        public override DTO.SubMaterialMng.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SubMaterialMng.EditFormData data = new DTO.SubMaterialMng.EditFormData();
            data.Data = new DTO.SubMaterialMng.SubMaterial();

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

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

            string SubMaterialUD = null;
            string SubMaterialNM = null;

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

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

            return(data);
        }
Exemple #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 (SubMaterialMngEntities context = CreateContext())
                {
                    SubMaterial dbItem = context.SubMaterial.FirstOrDefault(o => o.SubMaterialID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sub material not found!";
                        return(false);
                    }
                    else
                    {
                        var item = context.SubMaterialMng_SubMaterialCheck_View.Where(o => o.SubMaterialID == id).FirstOrDefault();
                        //CheckPermission
                        if (item.isUsed.Value == true)
                        {
                            throw new Exception("You can't delete because it used in item other!");
                        }
                        context.SubMaterial.Remove(dbItem);
                        context.SaveChanges();

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