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

            //try to get data
            try
            {
                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);
        }
Esempio n. 2
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
                    {
                        context.MaterialType.Remove(dbItem);
                        context.SaveChanges();

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

                return(false);
            }
        }
Esempio n. 3
0
        public override DTO.MaterialTypeMng.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.MaterialTypeMng.SearchFormData data = new DTO.MaterialTypeMng.SearchFormData();
            data.Data = new List <DTO.MaterialTypeMng.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);
        }