Example #1
0
        public async Task <IActionResult> PutMachine([FromRoute] int id, [FromBody] Machine machine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != machine.MachineId)
            {
                return(BadRequest());
            }

            _context.Entry(machine).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> PutTimesheet([FromRoute] int id, [FromBody] Timesheet timesheet)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Timesheet original = await _context.Timesheets.SingleOrDefaultAsync(m => m.TimesheetId == id);

            original.IsVerified = timesheet.IsVerified;

            try
            {
                original.Records?.Clear();
                await _context.SaveChangesAsync();

                original.Records = timesheet.Records;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TimesheetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <PaymentModel> SaveProductDetails(OrderModel model)
        {
            var storeProduct   = new Order().Assign(model);
            var productDetails = await _context.Products.FirstOrDefaultAsync(r => r.Id == model.productId);

            // var productDetails = await _context.Set<Product>().FirstOrDefaultAsync(r => r.Id == model.productId);
            productDetails.Quantity             = productDetails.Quantity - model.quantityBought;
            storeProduct.productOwnerId         = productDetails.UserId;
            storeProduct.currentPriceAtPurchase = productDetails.Price;
            if (model.OrderOption == OrderOption.Delivery.ToString())
            {
                storeProduct.OrderOption     = OrderOption.Delivery;
                storeProduct.deliveryAddress = model.deliveryAddress;
                storeProduct.buyerContact    = model.buyerContact;
            }

            _context.Order.Add(storeProduct);
            //_context.Set<Order>().Add(storeProduct);
            await _context.SaveChangesAsync();

            var paymentModel = new PaymentModel().Assign(storeProduct);

            paymentModel.callback_url = model.callbackUrl;
            paymentModel.amount       = model.TotalAmountPaid;
            paymentModel.reference    = model.reference;
            paymentModel.userId       = storeProduct.productOwnerId;


            return(paymentModel);
        }