private void addPlant(Quote q, QuoteDetailDTO plant) { var thisPlant = new PlantsForQuote(); thisPlant.Comment = plant.Comment; thisPlant.FormSize = plant.FormSize; thisPlant.PlantName = plant.PlantName; thisPlant.Price = plant.Price; thisPlant.Quantity = plant.Quantity; thisPlant.Active = plant.Active; thisPlant.QuoteId = q.QuoteId; thisPlant.BatchId = plant.BatchId; db.PlantsForQuotes.Add(thisPlant); }
public HttpResponseMessage Post(HttpRequestMessage request, [FromBody] NewQuoteDTO quote) { //if (!ModelState.IsValid) //{ // return request.CreateResponse(HttpStatusCode.BadRequest, quote); //} try { var thisQuote = new Quote(); thisQuote.Active = quote.Active; thisQuote.CustomerReference = quote.CustomerRef; //ParseExact is used as when trying to pass in dates from client side in set format, it needed changed to be saved into db? thisQuote.QuoteDate = DateTime.ParseExact(quote.Date, "dd/MM/yyyy", CultureInfo.InvariantCulture); thisQuote.QuoteExpiryDate = DateTime.ParseExact(quote.ExpiryDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); thisQuote.SiteReference = quote.SiteRef; thisQuote.QuotePrice = quote.TotalPrice; thisQuote.SalesOrder = quote.SalesOrder; thisQuote.Retail = quote.Retail; db.Quotes.Add(thisQuote); db.SaveChanges(); db.Entry(thisQuote).Reload(); var quoteId = thisQuote.QuoteId; foreach (var plant in quote.QuoteDetails) { var thisPlant = new PlantsForQuote(); thisPlant.Comment = plant.Comment; thisPlant.FormSize = plant.FormSize; thisPlant.PlantName = plant.PlantName; thisPlant.Price = plant.Price; thisPlant.Quantity = plant.Quantity; thisPlant.Active = plant.Active; thisPlant.BatchId = plant.BatchId; thisPlant.QuoteId = quoteId; thisPlant.PriceOverwritten = false; //TODO WILL NEED TO MAKE IT SO PRICES CAN BE OVERWRITTEN WHEN CREATING THEM db.PlantsForQuotes.Add(thisPlant); } db.SaveChanges(); return(request.CreateResponse(HttpStatusCode.OK, quoteId)); } catch (Exception ex) { return(request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
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)); }