public async Task <IActionResult> PutNonBills(int id, ApiNonBills nonBills)
        {
            if (id != nonBills.NonBillId)
            {
                return(BadRequest("Non-bill does not exist."));
            }

            var resource = new CoreNonBills
            {
                NonBillId = nonBills.NonBillId,
                Price     = nonBills.Price,
                StoreName = nonBills.StoreName,
                User      = await _userRepo.GetUserById(nonBills.UserId)
            };

            try
            {
                await _repo.UpdateNonBillAsync(resource);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await _repo.NonBillExistAsync(id))
                {
                    return(NotFound("Non-bill does not exist."));
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Non-bill updated!"));
        }
Ejemplo n.º 2
0
        public async Task UpdateNonBillAsync(CoreNonBills bill)
        {
            var newBill = Mapper.MapNonBills(bill);

            _conetext.Entry(newBill).State = EntityState.Modified;

            await Save();
        }
Ejemplo n.º 3
0
        public async Task <CoreNonBills> AddNonBillAsync(CoreNonBills bill)
        {
            var newBill = Mapper.MapNonBills(bill);

            _conetext.NonBills.Add(newBill);

            await Save();

            return(Mapper.MapNonBills(newBill));
        }
Ejemplo n.º 4
0
        /*  ************************
         *  *                      *
         *  *       Non-Bills      *
         *  *                      *
         *  ************************
         */

        public static NonBills MapNonBills(CoreNonBills bills)
        {
            return(new NonBills
            {
                NonBillId = bills.NonBillId,
                StoreName = bills.StoreName,
                Price = bills.Price,

                UserId = bills.User.UserId
            });
        }
Ejemplo n.º 5
0
        /*  ************************
         *  *                      *
         *  *       Non-Bills      *
         *  *                      *
         *  ************************
         */

        public static ApiNonBills MapNonBills(CoreNonBills bills)
        {
            return(new ApiNonBills
            {
                NonBillId = bills.NonBillId,
                StoreName = bills.StoreName,
                Price = bills.Price,

                UserId = bills.User.UserId,
                UserFirstName = bills.User.FirstName,
                UserLastName = bills.User.LastName
            });
        }
        public async Task <ActionResult> PostNonBills(ApiNonBills nonBills)
        {
            try
            {
                var resource = new CoreNonBills
                {
                    NonBillId = nonBills.NonBillId,
                    Price     = nonBills.Price,
                    StoreName = nonBills.StoreName,
                    User      = await _userRepo.GetUserById(nonBills.UserId)
                };

                await _repo.AddNonBillAsync(resource);

                return(Ok("Non-bill has been added!"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }