public bool DeleteTransportConditionItem(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; ReportDataObject ds = new ReportDataObject(); try { using (TransportOfferEntities context = CreateContext()) { var x = context.TransportConditionItem.Where(o => o.TransportConditionItemID == id).FirstOrDefault(); context.TransportConditionItem.Remove(x); context.SaveChanges(); } return(true); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success }; try { using (TransportOfferEntities context = CreateContext()) { var dbItem = context.TransportOffer.Where(o => o.TransportOfferID == id).FirstOrDefault(); context.TransportOffer.Remove(dbItem); context.SaveChanges(); } 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); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.TransportOfferDTO dtoTransportOffer = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.TransportOfferDTO>(); try { using (TransportOfferEntities context = CreateContext()) { TransportOffer dbItem = null; if (id > 0) { dbItem = context.TransportOffer.Where(o => o.TransportOfferID == id).FirstOrDefault(); } else { dbItem = new TransportOffer(); context.TransportOffer.Add(dbItem); } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoTransportOffer.File_HasChange.HasValue && dtoTransportOffer.File_HasChange.Value) { dtoTransportOffer.FileUD = fwFactory.CreateFilePointer(tempFolder, dtoTransportOffer.File_NewFile, dtoTransportOffer.FileUD, dtoTransportOffer.FriendlyName); } //convert dto to db converter.DTO2DB_TransportOffer(dtoTransportOffer, ref dbItem); dbItem.UpdatedBy = userId; //remove orphan context.TransportOfferCostDetail.Local.Where(o => o.TransportOffer == null).ToList().ForEach(o => context.TransportOfferCostDetail.Remove(o)); context.TransportOfferConditionDetail.Local.Where(o => o.TransportOffer == null).ToList().ForEach(o => context.TransportOfferConditionDetail.Remove(o)); //save data context.SaveChanges(); //get return data dtoItem = GetData(userId, dbItem.TransportOfferID, 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); } }
public DTO.TransportConditionItemDTO UpdateTransportConditionItem(int userId, int id, ref object dtoObjectItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.TransportConditionItemDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dtoObjectItem).ToObject <DTO.TransportConditionItemDTO>(); try { using (TransportOfferEntities context = CreateContext()) { TransportConditionItem dbItem = null; if (id == 0) { dbItem = new TransportConditionItem(); context.TransportConditionItem.Add(dbItem); } else { dbItem = context.TransportConditionItem.Where(o => o.TransportConditionItemID == id).FirstOrDefault(); } if (dbItem == null) { throw new Exception("data not found!"); } else { AutoMapper.Mapper.Map <DTO.TransportConditionItemDTO, TransportConditionItem>(dtoItem, dbItem); dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; //apply save data context.SaveChanges(); //get return data dtoItem = GetTransportConditionItem(dbItem.TransportConditionItemID, out notification); return(dtoItem); } } } 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(new TransportConditionItemDTO()); } }