Exemplo n.º 1
0
        //public List<Model.OrderAppointment> ToList(OrderAppointmentQuery query)
        //{
        //    var l =  OrderAppointment_BuildQuery(query)
        //        .AsNoTracking()
        //        .ToList();

        //    var result = l.Select(x => new Model.OrderAppointment
        //    {
        //        BillOfLading = x.BillOfLading,
        //        BoxesCount = x.BoxesCount,
        //        BoxSize = x.BoxSize,
        //        ConfirmationNumber = x.ConfirmationNumber,
        //        CustomerId = x.CustomerId,
        //        DivisionId = x.DivisionId,
        //        EndDate = x.EndDate,
        //        Notes = x.Notes,
        //        PickTicketId = x.PickTicketId,
        //        Pieces = x.Pieces,
        //        PtBulk = x.PtBulk,
        //        PurchaseOrderId = x.PurchaseOrderId,
        //        ScacCode = x.ScacCode,
        //        ShipFor = x.ShipFor,
        //        ShipTo = x.ShipTo,
        //        Size = x.Size,
        //        StartDate = x.StartDate,
        //        Status = x.Status,
        //        Weigth = x.Weigth,
        //        CustomerName = x.Customer !=null ? x.Customer.CompanyName : "",
        //        DivisionName = x.Division !=null ? x.Division.Description : ""
        //    });

        //    return result.ToList();

        //}

        public async Task <int> Update(Model.OrderAppointment orderAppointment)
        {
            try
            {
                var ptBulk = string.IsNullOrEmpty(orderAppointment.PtBulk) ? "" : orderAppointment.PtBulk;
                var entity = context.OrderAppointments.Where(x => x.PurchaseOrderId == orderAppointment.PurchaseOrderId && x.PickTicketId == orderAppointment.PickTicketId && x.CustomerId == orderAppointment.CustomerId && x.PtBulk == ptBulk).FirstOrDefault();

                if (entity != null)
                {
                    entity.Status = orderAppointment.Status;

                    if (!string.IsNullOrEmpty(orderAppointment.Notes))
                    {
                        entity.Notes = orderAppointment.Notes;
                    }

                    if (!string.IsNullOrEmpty(orderAppointment.ConfirmationNumber))
                    {
                        entity.ConfirmationNumber = orderAppointment.ConfirmationNumber;
                    }

                    if (orderAppointment.ShippingDateChanged.HasValue)
                    {
                        entity.ShippingDateChanged = orderAppointment.ShippingDateChanged.Value;
                    }

                    if (orderAppointment.ShipFor.HasValue)
                    {
                        entity.ShipFor = orderAppointment.ShipFor.Value;
                    }

                    return(await context.SaveChangesAsync());
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }

            return(0);
        }
 public async Task <int> Update(Model.OrderAppointment orderAppointment)
 {
     return(await Repository.Update(orderAppointment));
 }
Exemplo n.º 3
0
        public async Task <string> SetAppointment(Model.Appointment appointmentModel, Model.OrderAppointment order)
        {
            using (System.Data.Entity.DbContextTransaction dbTran = context.Database.BeginTransaction())
            {
                try
                {
                    var existingAppt = context.Appointments.Where(x => x.CustomerId == appointmentModel.CustomerId && x.PickTicketId == appointmentModel.PickTicket).FirstOrDefault();

                    if (existingAppt != null)
                    {
                        if (existingAppt.Status == "D")
                        {
                            // update the existing one, could be a previous cancelation
                            context.Appointments.Remove(existingAppt);
                        }
                        else
                        {
                            throw new ArgumentException($"Order with picticket {appointmentModel.PickTicket} for client {appointmentModel.CustomerId} already have an appointment {existingAppt.AppointmentNumber}");
                        }
                    }

                    Entities.Appointment appointment = new Entities.Appointment();
                    appointment.CustomerId   = appointmentModel.CustomerId;
                    appointment.DateAdd      = DateTime.Now;
                    appointment.PickTicketId = appointmentModel.PickTicket;
                    appointment.DivisionId   = appointmentModel.DivisionId;

                    appointment.ScacCode = appointmentModel.ScacCode;
                    // appointment.ShipDate = appointmentModel.ShippingDate.Value;
                    appointment.ShipTime          = new DateTime(appointmentModel.ShippingDate.Value.Year, appointmentModel.ShippingDate.Value.Month, appointmentModel.ShippingDate.Value.Day, appointmentModel.ShippingTime.Value.Hour, appointmentModel.ShippingTime.Value.Minute, 0);
                    appointment.AppointmentNumber = appointmentModel.AppointmentNumber;
                    appointment.DeliveryTypeId    = appointmentModel.DeliveryTypeId.Value;
                    appointment.UserName          = appointmentModel.UserName;
                    appointment.Pallets           = appointmentModel.Pallets;
                    appointment.DriverId          = appointmentModel.DriverId;
                    appointment.TruckId           = appointmentModel.TruckId;

                    if (appointmentModel.ShippingTimeLimit.HasValue)
                    {
                        appointment.ShippingTimeLimit = new DateTime(appointmentModel.ShippingDate.Value.Year, appointmentModel.ShippingDate.Value.Month, appointmentModel.ShippingDate.Value.Day, appointmentModel.ShippingTimeLimit.Value.Hour, appointmentModel.ShippingTimeLimit.Value.Minute, 0);
                    }

                    appointment.PtBulk = string.Empty;
                    if (!string.IsNullOrEmpty(appointmentModel.PtBulk))
                    {
                        appointment.PtBulk       = appointmentModel.PtBulk;
                        appointment.PickTicketId = appointmentModel.PtBulk;
                    }

                    context.Appointments.Add(appointment);


                    var ptBulk = string.IsNullOrEmpty(appointment.PtBulk) ? "" : appointment.PtBulk;


                    var entity = await context.OrderAppointments.Where(x => x.PurchaseOrderId == order.PurchaseOrderId && x.PickTicketId == appointment.PickTicketId && x.CustomerId == appointment.CustomerId && x.PtBulk == ptBulk).FirstOrDefaultAsync();

                    if (entity != null)
                    {
                        entity.Status  = 1;
                        entity.ShipFor = appointmentModel.ShippingDate.Value;
                        entity.Notes   = !string.IsNullOrEmpty(entity.Notes) ? $"{entity.Notes} / {order.Notes}" : order.Notes;
                    }

                    await context.SaveChangesAsync();

                    dbTran.Commit();

                    return(null);
                }
                catch (Exception exc)
                {
                    dbTran.Rollback();

                    return($"{exc.Message} : { exc.InnerException?.Message} ");
                }
            }
        }