public void DTO2DB(DTO.CatalogFileDTO dtoItem, ref CatalogFile dbItem, string TmpFile, int userId) { // employee AutoMapper.Mapper.Map <DTO.CatalogFileDTO, CatalogFile>(dtoItem, dbItem); if (dtoItem.HasChanged) { dbItem.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.NewFile, dbItem.FileUD, dtoItem.FriendlyName); } if (dtoItem.PLHasChanged) { dbItem.PriceListFileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.PLNewFile, dbItem.PriceListFileUD, dtoItem.PLFriendlyName); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.CatalogFileDTO dtoCatalogFile = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.CatalogFileDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (CatalogFileMngEntities context = CreateContext()) { CatalogFile dbItem = context.CatalogFile.FirstOrDefault(o => o.CatalogFileID == id); if (id > 0) { dbItem = context.CatalogFile.FirstOrDefault(o => o.CatalogFileID == id); } else { dbItem = new CatalogFile(); context.CatalogFile.Add(dbItem); } if (dbItem == null) { throw new Exception("Catalog file not found!"); } dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; converter.DTO2DB(dtoCatalogFile, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId); context.SaveChanges(); dtoItem = this.GetData(dbItem.CatalogFileID, out notification).Data; return(true); } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }