public void DTO2DB_SampleProduct(DTO.SampleProductDTO dtoItem, ref SampleProduct dbItem) { Mapper.Map <DTO.SampleProductDTO, SampleProduct>(dtoItem, dbItem); //Covert String to Dateime dbItem.StatusUpdatedDate = dtoItem.StatusUpdatedDate.ConvertStringToDateTime(); dbItem.FactoryDeadline = dtoItem.FactoryDeadline.ConvertStringToDateTime(); dbItem.ItemInfoUpdatedDate = dtoItem.ItemInfoUpdatedDate.ConvertStringToDateTime(); dbItem.ETADestination = dtoItem.ETADestination.ConvertStringToDateTime(); if (dtoItem.FactoryBreakdownDTO != null) { FactoryBreakdown dbFactoryBreakdown = dbItem.FactoryBreakdown.FirstOrDefault(); if (dbFactoryBreakdown != null) { Mapper.Map <DTO.FactoryBreakdownDTO, FactoryBreakdown>(dtoItem.FactoryBreakdownDTO, dbFactoryBreakdown); if (dtoItem.FactoryBreakdownDTO.FactoryBreakdownDetailDTOs != null) { foreach (var item in dtoItem.FactoryBreakdownDTO.FactoryBreakdownDetailDTOs) { FactoryBreakdownDetail dbFactoryBreakdownDetail = dbFactoryBreakdown.FactoryBreakdownDetail.FirstOrDefault(o => o.FactoryBreakdownDetailID == item.FactoryBreakdownDetailID); Mapper.Map <DTO.FactoryBreakdownDetailDTO, FactoryBreakdownDetail>(item, dbFactoryBreakdownDetail); } } } } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.SampleProductDTO dtoSampleProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.SampleProductDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SampleItemMngEntities context = CreateContext()) { SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id); if (dbItem == null) { notification.Message = "Sample Product not found!"; return(false); } else { dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoSampleProduct.ConcurrencyFlag))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2DB_SampleProduct(dtoSampleProduct, ref dbItem); context.SaveChanges(); dtoItem = GetData(dbItem.SampleProductID, out notification).Data; return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }