public IHttpActionResult Update(int id, DTO.ShowroomAreaMng.ShowroomArea dtoItem) { Library.DTO.Notification notification; Module.Framework.BLL fwBll = new Module.Framework.BLL(); if (id > 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanUpdate)) { return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED))); } else if (id == 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanCreate)) { return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED))); } // validation if (!Helper.CommonHelper.ValidateDTO <DTO.ShowroomAreaMng.ShowroomArea>(dtoItem, out notification)) { return(Ok(new Library.DTO.ReturnData <DTO.ShowroomAreaMng.ShowroomArea>() { Data = dtoItem, Message = notification })); } // save data BLL.ShowroomAreaMng bll = new BLL.ShowroomAreaMng(Helper.AuthHelper.GetCurrentUserFolder(ControllerContext)); bll.UpdateData(id, ref dtoItem, ControllerContext.GetAuthUserId(), out notification); return(Ok(new Library.DTO.ReturnData <DTO.ShowroomAreaMng.ShowroomArea>() { Data = dtoItem, Message = notification })); }
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); }