Beispiel #1
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (TransportInvoiceEntities context = CreateContext())
         {
             var dbItem = context.TransportInvoice.Where(o => o.TransportInvoiceID == id).FirstOrDefault();
             context.TransportInvoice.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);
     }
 }
Beispiel #2
0
 public bool SetInvoiceStatus(int userID, int statusID, int transportInvoiceID, out Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success, Message = "Set status success"
     };
     try
     {
         using (TransportInvoiceEntities context = CreateContext())
         {
             if (transportInvoiceID <= 0)
             {
                 throw new Exception("You have to save data before set status");
             }
             var x = context.TransportInvoice.Where(o => o.TransportInvoiceID == transportInvoiceID).FirstOrDefault();
             x.InvoiceStatusID   = statusID;
             x.StatusUpdatedBy   = userID;
             x.StatusUpdatedDate = DateTime.Now;
             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);
     }
 }
Beispiel #3
0
 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.TransportInvoiceDTO dtoTransportInvoice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.TransportInvoiceDTO>();
     try
     {
         using (TransportInvoiceEntities context = CreateContext())
         {
             TransportInvoice dbItem = null;
             if (id > 0)
             {
                 dbItem             = context.TransportInvoice.Where(o => o.TransportInvoiceID == id).FirstOrDefault();
                 dbItem.UpdatedBy   = userId;
                 dbItem.UpdatedDate = DateTime.Now;
             }
             else
             {
                 dbItem             = new TransportInvoice();
                 dbItem.CreatedBy   = userId;
                 dbItem.CreatedDate = DateTime.Now;
                 context.TransportInvoice.Add(dbItem);
             }
             if (dbItem == null)
             {
                 notification.Message = "data not found!";
                 return(false);
             }
             else
             {
                 //convert dto to db
                 converter.DTO2DB_TransportInvoice(dtoTransportInvoice, ref dbItem);
                 //remove orphan
                 context.TransportInvoiceContainerDetail.Local.Where(o => o.TransportInvoiceDetail == null).ToList().ForEach(o => context.TransportInvoiceContainerDetail.Remove(o));
                 context.TransportInvoiceDetail.Local.Where(o => o.TransportInvoice == null).ToList().ForEach(o => context.TransportInvoiceDetail.Remove(o));
                 //save data
                 context.SaveChanges();
                 //get return data
                 dtoItem = GetData(userId, dbItem.TransportInvoiceID, dbItem.BookingID, 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);
     }
 }