public HttpResponseMessage Post(HttpRequestMessage request, [FromBody] SelectedPickListDTO picklist)
        {
            if (!ModelState.IsValid)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest, picklist));
            }

            try
            {
                var newPickList = new Picklist
                {
                    QuoteId           = picklist.QuoteId,
                    DispatchDate      = picklist.DipatchDate,
                    DeliveryAddress   = picklist.DeliveryAddress,
                    DeliveryNeeded    = picklist.DeliveryNeeded,
                    IsPicked          = picklist.IsPicked,
                    IsPacked          = picklist.IsPacked,
                    IsDelivered       = picklist.IsPacked,
                    Comment           = picklist.Comment,
                    EstimatedDelivery = picklist.EsimatedDelivery,
                    Active            = true //Default to true as initial save
                };

                db.Picklists.Add(newPickList);
                db.SaveChanges();
                db.Entry(newPickList).Reload();

                var pickListId = newPickList.PicklistId;
                foreach (var plant in picklist.PickListPlants)
                {
                    var thisPlant = new PlantsForPicklist
                    {
                        PicklistId       = pickListId,
                        PlantForQuoteId  = plant.PlantForQuoteId,
                        PlantName        = plant.PlantName,
                        FormSize         = plant.FormSize,
                        QuantityToPick   = plant.QuantityToPick,
                        SubbedFor        = plant.SubbedFor,
                        isSubbed         = plant.IsSubbed,
                        DispatchLocation = plant.DispatchLocation,
                        Active           = true
                    };
                    db.PlantsForPicklists.Add(thisPlant);
                }
                db.SaveChanges();


                return(request.CreateResponse(HttpStatusCode.OK, picklist));
            }
            catch (Exception ex)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Esempio n. 2
0
        public IHttpActionResult PutAddItemToPicklist(AddItemPicklistModal newItem)
        {
            if (newItem != null)
            {
                var currentBatch    = db.Batches.FirstOrDefault(x => x.Id == newItem.BatchId);
                var currentPicklist = db.Picklists.FirstOrDefault(x => x.PicklistId == newItem.PicklistId);

                if (currentPicklist != null)
                {
                    var plantForQuoteToInsert = new PlantsForQuote()  //insert new plant into quote to get id
                    {
                        PlantName = newItem.PlantName,
                        FormSize  = newItem.FormSize,
                        Comment   = newItem.Comment,
                        Price     = currentBatch.WholesalePrice ?? 0,
                        Quantity  = newItem.QuantityToPick,
                        QuoteId   = currentPicklist.QuoteId,
                        Active    = true,
                    };
                    db.PlantsForQuotes.Add(plantForQuoteToInsert);
                    db.SaveChanges();
                    db.Entry(plantForQuoteToInsert).Reload(); //used to get the current PlantForQuoteId

                    var plantForPickListToInsert = new PlantsForPicklist()
                    {
                        PicklistId       = newItem.PicklistId,
                        PlantForQuoteId  = plantForQuoteToInsert.PlantsForQuoteId,
                        PlantName        = newItem.PlantName,
                        FormSize         = newItem.FormSize,
                        QuantityToPick   = newItem.QuantityToPick,
                        OriginalItem     = null,
                        DispatchLocation = null,
                        Active           = true,
                        IsSubbed         = false,
                        BatchId          = newItem.BatchId,
                        QuantityPicked   = 0,
                    };
                    db.PlantsForPicklists.Add(plantForPickListToInsert);
                    db.SaveChanges();

                    return(StatusCode(HttpStatusCode.OK));
                }
            }
            return(StatusCode(HttpStatusCode.BadRequest));
        }
Esempio n. 3
0
        private Decimal GetPrice(PlantsForPicklist p)
        {
            Batch batch = db.Batch.Find(p.BatchId);

            return(Convert.ToDecimal(batch.BuyPrice / 100));
        }
Esempio n. 4
0
        public HttpResponseMessage Post(HttpRequestMessage request, [FromBody] SelectedPickListDTO picklist)
        {
            if (!ModelState.IsValid)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest, picklist));
            }

            try
            {
                var newPickList = new Picklist
                {
                    QuoteId           = picklist.QuoteId,
                    DispatchDate      = DateTime.ParseExact(picklist.DispatchDate, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    DeliveryAddress   = picklist.DeliveryAddress,
                    DeliveryNeeded    = picklist.DeliveryNeeded,
                    IsPicked          = picklist.IsPicked,
                    IsAllocated       = picklist.IsAllocated,
                    IsDelivered       = picklist.IsDelivered,
                    Comment           = picklist.Comment,
                    EstimatedDelivery = picklist.EstimatedDelivery,
                    Active            = true //Default to true as initial save
                };

                db.Picklists.Add(newPickList);
                db.SaveChanges();
                db.Entry(newPickList).Reload();

                var pickListId = newPickList.PicklistId;
                foreach (var plant in picklist.PickListPlants)
                {
                    var needsPurchasing = false;
                    if (plant.Location == "PB")
                    {
                        needsPurchasing = true;
                    }

                    var thisPlant = new PlantsForPicklist
                    {
                        PicklistId       = pickListId,
                        PlantForQuoteId  = plant.PlantForQuoteId,
                        BatchId          = plant.BatchId,
                        PlantName        = plant.PlantName,
                        FormSize         = plant.FormSize,
                        QuantityToPick   = plant.QuantityToPick,
                        IsSubbed         = plant.IsSubbed,
                        DispatchLocation = plant.DispatchLocation,
                        QuantityPicked   = 0, //Default this to 0 because none will have been picked on creation??
                        NeedsPurchasing  = needsPurchasing,
                        Active           = true
                    };
                    db.PlantsForPicklists.Add(thisPlant);
                }
                db.SaveChanges();


                return(request.CreateResponse(HttpStatusCode.OK, picklist));
            }
            catch (Exception ex)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }