Esempio n. 1
0
        public HttpResponseMessage Post([FromBody] SellInvoice inv)
        {
            String resp     = "{\"Response\":\"Undefine\"}";
            var    response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var ctx = new GASEntities();

                if (inv != null)
                {
                    ctx.SellInvoices.Add(inv);
                    ctx.SaveChanges();

                    resp = "{\"Response\":\"OK\"}";
                }
            }
            catch (Exception ex)
            {
                int a = 1;
                resp     = "{\"Response\":\"Fail\"}";
                response = Request.CreateResponse(HttpStatusCode.InternalServerError);
            }

            // var response = Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json");
            return(response);
        }
        private void SellInvoice_Click(object sender, RoutedEventArgs e)
        {
            SellInvoice rec = new SellInvoice();

            rec.Show();
            this.Close();
        }
Esempio n. 3
0
        public int CreateSellInvoice([FromBody] IInvoice sellInvoice)
        {
            var newInvoice = new SellInvoice();

            var user = this.Request.GetMyUser();

            newInvoice.Invoice        = new Invoice();
            newInvoice.Invoice.UserId = user.Id;

            newInvoice.CustomerId = sellInvoice.TarafHesabId;

            var fee = 0;

            foreach (var item in sellInvoice.Items)
            {
                var good = db.Good.First(x => x.Id == item.GoodId);
                if (item.Quantity > good.Quantity)
                {
                    throw new Exception("Not enough quantity in the inventory");
                }

                var price = Convert.ToInt32(good.Price * (100 - good.Discount) / 100);
                fee += price;

                var invoiceItem = new InvoiceItem
                {
                    GoodId    = item.GoodId,
                    GoodName  = good.Name,
                    Discount  = good.Discount,
                    GoodPrice = good.Price,
                    Quantity  = good.Quantity,
                };

                invoiceItem.TotalPrice = invoiceItem.GetTotalPrice();
                newInvoice.Invoice.InvoiceItem.Add(invoiceItem);
            }
            // TODO Calculate discount;
            newInvoice.Invoice.Fee = fee;

            db.SellInvoice.Add(newInvoice);
            db.SaveChanges();

            IInventory inventory = new InventoryController();

            foreach (var item in sellInvoice.Items)
            {
                inventory.IncreaseGoodQuantity(item.GoodId, -item.Quantity);
            }
            return(newInvoice.InvoiceId);
        }