public bool Delete(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (TransportationServiceMngEntities context = CreateContext()) { TransportationService dbItem = context.TransportationService.FirstOrDefault(o => o.TransportationServiceID == id); if (dbItem == null) { notification.Message = "Transportation Service not found!"; return(false); } else { context.TransportationService.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public bool Update(int iRequesterID, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; DTO.TransportationServiceData dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.TransportationServiceData>(); try { using (var context = CreateContext()) { TransportationService transportationService = null; if (id == 0) { transportationService = new TransportationService(); context.TransportationService.Add(transportationService); } else { transportationService = context.TransportationService.FirstOrDefault(o => o.TransportationServiceID == id); } if (transportationService == null) { notification.Message = "Transportation Service not found!"; return(false); } else { converter.DTO2BD_TransportationService(dtoItems, ref transportationService); transportationService.UpdatedDate = DateTime.Now; transportationService.UpdatedBy = iRequesterID; context.SaveChanges(); dtoItem = GetEditData(transportationService.TransportationServiceID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2BD_TransportationService(DTO.TransportationServiceData dtoItem, ref TransportationService dbItem) { AutoMapper.Mapper.Map <DTO.TransportationServiceData, TransportationService>(dtoItem, dbItem); }