Example #1
0
        // POST: api/JobCard
        public IHttpActionResult Post([FromBody] JsonJobCardMappingObject quotationMap)
        {
            var quoteFromView       = _context.Quotations.SingleOrDefault(s => s.Id == quotationMap.QuotationId);
            var stockItemQuanitites = _context.StockItemQuantities.Where(s => s.QuotationId == quoteFromView.Id);
            //
            var stockItemList = new List <StockItem>();

            //
            foreach (var stockItem in stockItemQuanitites)
            {
                _context.StockItemQuantities.Remove(stockItem);
                _context.SaveChanges();
            }
            //
            foreach (var stockItem in quotationMap.Items)
            {
                StockItemQuantity quantityItem = new StockItemQuantity();
                quantityItem.StockItemId = stockItem.Id;
                quantityItem.Quantity    = stockItem.Quantity;
                quantityItem.QuotationId = quoteFromView.Id;
                //
                _context.Entry(quantityItem).State = EntityState.Modified;
                _context.SaveChanges();
                //
            }
            return(Ok());
        }
Example #2
0
        public IHttpActionResult Post([FromBody] JsonQuoteMappingObject quotationMap)
        {
            try
            {
                //var person = _context.Customers.SingleOrDefault(s => s.Id == quotationMap.CustomerId);
                //
                var quote = new Quotation();
                var stockItemQuantities = new List <StockItemQuantity>();
                //
                quote.CustomerId = quotationMap.CustomerId;
                quote.CreatedAt  = DateTime.Now;
                //
                //var stockItemList = new List<StockItem>();
                //
                _context.Quotations.Add(quote);
                _context.SaveChanges();
                int quoteId = quote.Id;
                //
                double total = 0;

                foreach (var stockItem in quotationMap.OrderArray)
                {
                    var stockItemQuantity = new StockItemQuantity();
                    stockItemQuantity.StockItemId = stockItem.Identifier;
                    stockItemQuantity.Quantity    = stockItem.Quantity;
                    stockItemQuantity.QuotationId = quoteId;
                    //
                    total += stockItem.Amount;
                    //
                    _context.StockItemQuantities.Add(stockItemQuantity);
                    _context.SaveChanges();
                }

                quote.Total = total;
                _context.Entry(quote).State = EntityState.Modified;
                _context.SaveChanges();
                //
                Mailer.SendApprovalRequest(quote.Id);
                return(Ok());
            }
            catch (Exception e)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }