Пример #1
0
        private void ChangeItem_Click(object sender, EventArgs e)
        {
            if (_selectedReceipt == null)
            {
                return;
            }
            var changeForm = new ReceiptEdit(_selectedReceipt);

            changeForm.FormClosed += ChangeForm_FormClosed;
            ;
            changeForm.Show();
        }
Пример #2
0
        public void UpdateReceipt(int userId, int id, ReceiptEdit receiptEdit)
        {
            var receipt = _context.Receipts.FirstOrDefault(r => r.UserID == userId && r.ID == id);

            receipt.PurchaseDate = DateTime.Parse(receiptEdit.Date);
            receipt.ShopID       = receiptEdit.ShopId;

            //Check products

            //Current products
            var currentProducts = _context.ReceiptProducts.Where(rp => rp.ReceiptID == id).ToList();

            foreach (var receiptProduct in receiptEdit.Products)
            {
                //Add if new
                if (receiptProduct.ReceiptProductId == -1)
                {
                    var receiptProductObj = new ReceiptProduct()
                    {
                        Amount    = receiptProduct.Amount,
                        Price     = receiptProduct.Price,
                        ProductID = receiptProduct.ProductId,
                        ReceiptID = id
                    };
                    _context.ReceiptProducts.Add(receiptProductObj);
                    _context.SaveChanges();
                }
                //Only edit
                else
                {
                    var current =
                        _context.ReceiptProducts.FirstOrDefault(rp => rp.ID == receiptProduct.ReceiptProductId);
                    current.Amount    = receiptProduct.Amount;
                    current.Price     = receiptProduct.Price;
                    current.ProductID = receiptProduct.ProductId;
                    _context.SaveChanges();
                }
            }

            //Look for products to delete

            foreach (var currentProduct in currentProducts)
            {
                if (receiptEdit.Products.All(p => p.ReceiptProductId != currentProduct.ID))
                {
                    _context.ReceiptProducts.Remove(currentProduct);
                    _context.SaveChanges();
                }
            }
        }
Пример #3
0
        public bool UpdateReceipt(ReceiptEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Receipts
                    .Single(e => e.FKRentalID == model.ReceiptID);

                entity.FKRentalID      = model.ReceiptID;
                entity.AmountPaid      = model.AmountPaid;
                entity.ActualStartDate = model.ActualStartDate;
                entity.ActualEndDate   = model.ActualEndDate;
                return(ctx.SaveChanges() == 1);
            }
        }
Пример #4
0
        //private CustomerRatingService CreateCustomerRatingService()
        //{
        //    var userId = Guid.Parse(User.Identity.GetUserId());
        //    var customerRatingService = new CustomerRatingService();
        //    return customerRatingService;
        //}


        /// <summary>
        /// Changes an existing Receipt object in the Database
        /// </summary>
        /// <param name="editReciept">The new Receipt, with same ID, to replace existing Receipt in Database</param>
        /// <returns></returns>
        public IHttpActionResult Put(ReceiptEdit editReciept)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateReceiptService();

            if (!service.UpdateReceipt(editReciept))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #5
0
        public async Task <IActionResult> PutReceipt([FromRoute] int userId, [FromRoute] int id, [FromBody] ReceiptEdit receiptEdit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _receiptHelper.UpdateReceipt(userId, id, receiptEdit);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReceiptExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }