Exemple #1
0
        public override bool UpdateData(int id, ref DTO.ShowroomAreaMng.ShowroomArea dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShowroomAreaMngEntities context = CreateContext())
                {
                    ShowroomArea dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ShowroomArea();
                        context.ShowroomArea.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ShowroomArea.FirstOrDefault(o => o.ShowroomAreaID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "data 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);
                        //}

                        //convert dto to db
                        converter.DTO2DB_ShowroomArea(dtoItem, ref dbItem, this._TempFolder);
                        //reove orphan
                        context.ShowroomAreaImage.Local.Where(o => o.ShowroomArea == null).ToList().ForEach(o => context.ShowroomAreaImage.Remove(o));
                        //save data
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.ShowroomAreaID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
Exemple #2
0
        public void DTO2DB_ShowroomArea(DTO.ShowroomAreaMng.ShowroomArea dtoItem, ref ShowroomArea dbItem, string tempFolder)
        {
            List <ShowroomAreaImage> image_tobedeleted = new List <ShowroomAreaImage>();

            if (dtoItem.ShowroomAreaImages != null)
            {
                //CHECK
                foreach (var dbDetail in dbItem.ShowroomAreaImage.Where(o => !dtoItem.ShowroomAreaImages.Select(s => s.ShowroomAreaImageID).Contains(o.ShowroomAreaImageID)))
                {
                    image_tobedeleted.Add(dbDetail);
                }
                foreach (var dbDetail in image_tobedeleted)
                {
                    dbItem.ShowroomAreaImage.Remove(dbDetail);
                }
                //MAP
                foreach (var item in dtoItem.ShowroomAreaImages)
                {
                    if (item.ImageFile_HasChange.HasValue && item.ImageFile_HasChange.Value)
                    {
                        item.ImageFile = fwFactory.CreateFilePointer(tempFolder, item.ImageFile_NewFile, item.ImageFile);
                    }

                    ShowroomAreaImage dbAreaImage;
                    if (item.ShowroomAreaImageID < 0)
                    {
                        dbAreaImage = new ShowroomAreaImage();
                        dbItem.ShowroomAreaImage.Add(dbAreaImage);
                    }
                    else
                    {
                        dbAreaImage = dbItem.ShowroomAreaImage.FirstOrDefault(o => o.ShowroomAreaImageID == item.ShowroomAreaImageID);
                    }

                    if (dbAreaImage != null)
                    {
                        AutoMapper.Mapper.Map <DTO.ShowroomAreaMng.ShowroomAreaImage, ShowroomAreaImage>(item, dbAreaImage);
                    }
                }
            }
            AutoMapper.Mapper.Map <DTO.ShowroomAreaMng.ShowroomArea, ShowroomArea>(dtoItem, dbItem);
        }