Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 public void DTO2BD_TransportationService(DTO.TransportationServiceData dtoItem, ref TransportationService dbItem)
 {
     AutoMapper.Mapper.Map <DTO.TransportationServiceData, TransportationService>(dtoItem, dbItem);
 }