Esempio n. 1
0
        public async Task <IActionResult> Update([FromRoute] Guid billId, [FromBody] UpdateBillRequest updateRequest)
        {
            var bill    = updateRequest.ToBill();
            var updated = await _billService.UpdateBillAsync(bill);

            if (!updated)
            {
                return(NotFound());
            }

            return(Ok(bill.ToBillResponse()));
        }
Esempio n. 2
0
 public static Bill ToBill(this UpdateBillRequest updateRequest)
 {
     return(new Bill
     {
         Vendor = updateRequest.Vendor,
         Occurance = updateRequest.Occurance,
         PaymentType = updateRequest.PaymentType,
         IsPaid = updateRequest.IsPaid,
         PaidDate = updateRequest.PaidDate,
         Notes = updateRequest.Notes
     });
 }
Esempio n. 3
0
        public CommunicationResponse UpdateBill([FromBody] UpdateBillRequest billRequest)
        {
            var response = new AddBillResponse();

            try
            {
                if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false)
                {
                    response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID);
                    return(response);
                }

                ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString());
                if (user.HouseId == 0)
                {
                    response.AddError("You must belong to a household to update bills", ErrorCode.USER_NOT_IN_HOUSEHOLD);
                    return(response);
                }
                UpdateBill bill = new UpdateBill
                {
                    Name          = billRequest.Name,
                    Id            = billRequest.Id,
                    Due           = billRequest.Due,
                    PeopleIds     = billRequest.PeopleIds,
                    TotalAmount   = billRequest.TotalAmount,
                    RecurringType = billRequest.RecurringType
                };
                var rowUpdated = _billRepository.UpdateBill(bill);

                if (rowUpdated == false)
                {
                    response.AddError("The given Bill Id does not correspond to an existing Bill");
                    return(response);
                }

                response.Notifications = new List <string>
                {
                    $"The bill '{billRequest.Name}' has been updated"
                };
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", billRequest, exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", billRequest);
            }

            return(response);
        }
        public async Task <IActionResult> UpdateBill([FromBody] UpdateBillRequest updateBillRequest)
        {
            var bill = await _billRepository.GetBillByBillId(updateBillRequest.Id);

            bill.BillPurposeId = (await _billRepository.GetBillPurposes()).SingleOrDefault(p => p.Name == updateBillRequest.BillPurpose).Id;
            bill.TotalAmount   = updateBillRequest.TotalAmount;
            bill.DateTime      = updateBillRequest.DateTime;
            bill.Remarks       = updateBillRequest.Remarks;

            var billSharingsInDb = await _billRepository.GetBillSharingsByBillId(updateBillRequest.Id);

            foreach (var billSharing in updateBillRequest.BillSharings)
            {
                var billSharingsIdsInDb = billSharingsInDb.Select(bs => bs.Id);

                //update bill sharings
                if (billSharingsIdsInDb.Contains(billSharing.Id))
                {
                    var billSharingInDb = billSharingsInDb.SingleOrDefault(bs => bs.Id == billSharing.Id);
                    if (!decimal.Equals(billSharingInDb.Amount, billSharing.Amount))
                    {
                        billSharingInDb.Amount = billSharing.Amount;
                    }
                }
                //remove old bill sharings
            }

            //update own share
            var ownSharing = billSharingsInDb.SingleOrDefault(bs => bs.SharerId == updateBillRequest.InitiatorId);

            if (!decimal.Equals(ownSharing.Amount, updateBillRequest.BalanceAmount))
            {
                ownSharing.Amount = updateBillRequest.BalanceAmount;
            }

            //add new bill sharings


            await _unitOfWork.CompleteAsync();

            return(Ok("ok"));
        }
Esempio n. 5
0
 public async Task <AbstractAnswer <Bill> > UpdateBillAsync(UpdateBillRequest request)
 {
     return(await mediator.Send(request));
 }