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