Exemplo n.º 1
0
        public CommunicationResponse UpdateToDoItem([FromBody] UpdateToDoRequest toDoRequest)
        {
            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);
                }

                _toDoRepository.UpdateToDoTask(toDoRequest);

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

            return(response);
        }
Exemplo n.º 2
0
        public AddBillResponse AddBill([FromBody] AddBillRequest 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 add bills", ErrorCode.USER_NOT_IN_HOUSEHOLD);
                    return(response);
                }

                AddBill bill = new AddBill
                {
                    Name          = billRequest.Name,
                    Due           = billRequest.Due,
                    PeopleIds     = billRequest.PeopleIds,
                    RecurringType = billRequest.RecurringType,
                    TotalAmount   = billRequest.TotalAmount,
                    HouseId       = user.HouseId
                };
                BillValidator.CheckIfValidBill(bill);
                response.Id = _billRepository.AddBill(bill);

                if (user.HouseId == 1)
                {
                    _discordService.AddBillNotification(billRequest.Name, billRequest.Due, billRequest.TotalAmount);
                }

                response.Notifications = new List <string>
                {
                    $"The bill '{billRequest.Name}' has been added"
                };
            }
            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);
        }
Exemplo 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);
        }