Ejemplo n.º 1
0
        public override DTO.CushionMng.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.CushionMng.EditFormData data = new DTO.CushionMng.EditFormData();
            data.Data    = new DTO.CushionMng.Cushion();
            data.Seasons = new List <DTO.Support.Season>();

            //try to get data
            try
            {
                using (CushionMngEntities context = CreateContext())
                {
                    data.Data    = converter.DB2DTO_Cushion(context.CushionMng_Cushion_View.FirstOrDefault(o => o.CushionID == id));
                    data.Seasons = supportFactory.GetSeason().ToList();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Ejemplo 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 (CushionMngEntities context = CreateContext())
                {
                    Cushion dbItem = context.Cushion.FirstOrDefault(o => o.CushionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Cushion not found!";
                        return(false);
                    }
                    else
                    {
                        context.Cushion.Remove(dbItem);
                        context.SaveChanges();

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

                return(false);
            }
        }
Ejemplo n.º 3
0
        public override bool UpdateData(int id, ref DTO.CushionMng.Cushion dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (CushionMngEntities context = CreateContext())
                {
                    Cushion dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Cushion();
                        context.Cushion.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Cushion.FirstOrDefault(o => o.CushionID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Cushion not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        converter.DTO2BD(dtoItem, ref dbItem);
                        context.SaveChanges();

                        // processing image
                        if (dtoItem.ImageFile_HasChange)
                        {
                            dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile);
                        }
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.CushionID, out notification).Data;

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

                return(false);
            }
        }
Ejemplo n.º 4
0
        public override DTO.CushionMng.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.CushionMng.SearchFormData data = new DTO.CushionMng.SearchFormData();
            data.Data = new List <DTO.CushionMng.CushionSearchResult>();
            totalRows = 0;

            string CushionUD  = null;
            string CushionNM  = null;
            string Season     = null;
            bool?  IsStandard = null;

            if (filters.ContainsKey("CushionUD") && !string.IsNullOrEmpty(filters["CushionUD"].ToString()))
            {
                CushionUD = filters["CushionUD"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("CushionNM") && !string.IsNullOrEmpty(filters["CushionNM"].ToString()))
            {
                CushionNM = filters["CushionNM"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString()))
            {
                Season = filters["Season"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("IsStandard") && filters["IsStandard"] != null && !string.IsNullOrEmpty(filters["IsStandard"].ToString()))
            {
                IsStandard = (filters["IsStandard"].ToString() == "true") ? true : false;
            }

            //try to get data
            try
            {
                using (CushionMngEntities context = CreateContext())
                {
                    totalRows = context.CushionMng_function_SearchCushion(CushionUD, CushionNM, Season, IsStandard, orderBy, orderDirection).Count();
                    var result = context.CushionMng_function_SearchCushion(CushionUD, CushionNM, Season, IsStandard, orderBy, orderDirection);
                    data.Data = converter.DB2DTO_CushionSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }