public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.AVFSupplier dtoAVFSupplier = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.AVFSupplier>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (AVFSupplierMngEntities context = CreateContext()) { AVFSupplier dbItem = null; if (id == 0) { dbItem = new AVFSupplier(); context.AVFSupplier.Add(dbItem); } else { dbItem = context.AVFSupplier.FirstOrDefault(o => o.AVFSupplierID == id); } if (dbItem == null) { notification.Message = "Profile not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoAVFSupplier.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoAVFSupplier, ref dbItem); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(dbItem.AVFSupplierID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2BD(DTO.AVFSupplier dtoItem, ref AVFSupplier dbItem) { AutoMapper.Mapper.Map <DTO.AVFSupplier, AVFSupplier>(dtoItem, dbItem); dbItem.UpdatedDate = DateTime.Now; }
public DTO.AVFSupplier DB2DTO_AVFSupplier(AVFSupplierMng_Supplier_View dbItem) { DTO.AVFSupplier dtoItem = AutoMapper.Mapper.Map <AVFSupplierMng_Supplier_View, DTO.AVFSupplier>(dbItem); dtoItem.ConcurrencyFlag_String = Convert.ToBase64String(dtoItem.ConcurrencyFlag); return(dtoItem); }