/// <summary> /// Deletes a bill. /// </summary> /// <param name="request">The request.</param> /// <returns>The response object.</returns> public async Task <DeleteBillResponse> DeleteBill(DeleteBillRequest request) { return(await Orchestrate(async delegate { var success = await repository.DeleteBill(request.BillId); return assembler.NewDeleteBillResponse(success, request.RequestReference); }, request)); }
public IActionResult DeleteBill(int id) { var bill = _billRepository.DeleteBill(id); if (bill == null) { return(BadRequest()); } return(Ok()); }
public bool DeleteBill(HoaDon billToDelete) { try { _billrepository.DeleteBill(billToDelete); } catch { return(false); } return(true); }
public CommunicationResponse DeleteBill([FromBody] DeleteBillRequest deleteBillRequest) { var response = new CommunicationResponse(); 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 delete bills", ErrorCode.USER_NOT_IN_HOUSEHOLD); return(response); } var rowUpdated = _billRepository.DeleteBill(deleteBillRequest.BillId); if (rowUpdated == false) { response.AddError($"Cannot delete the bill (ID: {deleteBillRequest.BillId}) because it does not exist"); return(response); } response.Notifications = new List <string> { $"The bill (ID: {deleteBillRequest.BillId}) has been deleted" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", deleteBillRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", deleteBillRequest); } return(response); }
public void DeleteBill(int id) { _billRepository.DeleteBill(id); }
public void SetUp() { userId = Guid.NewGuid(); expenditureId = Guid.NewGuid(); validData = new List <BillDataModel>(); invalidDeleteBillRequest = new DeleteBillRequest(); invalidEditBillRequest = new EditBillRequest(); invalidGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest(); invalidGetBillsForUserRequest = new GetBillsForUserRequest(); invalidGetBillRequest = new GetBillRequest(); invalidAddBillRequest = new AddBillRequest(); validBillDataModel = new BillDataModel { Amount = 1, Category = new CategoryDataModel { CreationTime = DateTime.Now, Id = Guid.NewGuid(), Name = "TEST" }, CreationTime = DateTime.Now, CategoryId = Guid.NewGuid(), Id = Guid.NewGuid(), UserId = Guid.NewGuid() }; expenditureProxy = new BillProxy { Amount = 1.0, Category = new CategoryProxy { Id = Guid.NewGuid(), Name = "TEST" }, CategoryId = Guid.NewGuid(), Id = Guid.NewGuid(), UserId = Guid.NewGuid() }; validDeleteBillRequest = new DeleteBillRequest { BillId = Guid.NewGuid(), Username = "******" }; validGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest { MonthNumber = 1, UserId = userId, Username = "******" }; validAddBillRequest = new AddBillRequest { Bill = expenditureProxy, Username = "******" }; validGetBillsForUserRequest = new GetBillsForUserRequest { UserId = userId, Username = "******" }; validGetBillRequest = new GetBillRequest { BillId = expenditureId, Username = "******" }; validEditBillRequest = new EditBillRequest { Bill = expenditureProxy, Username = "******" }; validGetBillsForUserResponse = new GetBillsForUserResponse { Bills = new List <BillProxy> { expenditureProxy } }; validGetBillResponse = new GetBillResponse { Bill = expenditureProxy }; validAddBillResponse = new AddBillResponse { Bill = expenditureProxy }; validEditBillResponse = new EditBillResponse { Bill = expenditureProxy }; validDeleteBillResponse = new DeleteBillResponse { DeleteSuccess = true }; validGetBillsForUserForMonthResponse = new GetBillsForUserForMonthResponse { Data = new List <KeyValuePair <DateTime, double> > { new KeyValuePair <DateTime, double>(DateTime.Now, 1.0) } }; assembler = Substitute.For <IBillAssembler>(); repository = Substitute.For <IBillRepository>(); dataTransformer = Substitute.For <IBillDataTransformer>(); repository.AddBill(validBillDataModel).Returns(validBillDataModel); repository.AddBill(null).Throws(new Exception("TEST")); repository.DeleteBill(validDeleteBillRequest.BillId).Returns(true); repository.DeleteBill(invalidDeleteBillRequest.BillId).Throws(new Exception("TEST")); repository.EditBill(validBillDataModel).Returns(validBillDataModel); repository.EditBill(null).Throws(new Exception("TEST")); repository.GetBill(expenditureId).Returns(validBillDataModel); repository.GetBill(Guid.Empty).Throws(new Exception("TEST")); repository.GetBillsForUser(validGetBillsForUserRequest.UserId) .Returns(new List <BillDataModel> { validBillDataModel }); repository.GetBillsForUser(Guid.Empty).Throws(new Exception("TEST")); dataTransformer.GetOutgoingBillsForMonth(Arg.Any <int>(), Arg.Any <List <BillDataModel> >()) .Returns( new List <KeyValuePair <DateTime, double> > { new KeyValuePair <DateTime, double>(DateTime.Now, 1.0) }); dataTransformer.GetBillCategoryChartData(Arg.Any <List <BillDataModel> >()) .Returns(new List <KeyValuePair <string, int> > { new KeyValuePair <string, int>() }); assembler.NewAddBillResponse(validBillDataModel, validAddBillRequest.RequestReference) .Returns(validAddBillResponse); assembler.NewDeleteBillResponse(true, validDeleteBillRequest.BillId) .Returns(validDeleteBillResponse); assembler.NewEditBillResponse( validBillDataModel, validEditBillRequest.RequestReference) .Returns(validEditBillResponse); assembler.NewBillDataModel(expenditureProxy).Returns(validBillDataModel); assembler.NewGetBillsForUserForMonthResponse( Arg.Any <List <KeyValuePair <DateTime, double> > >(), validGetBillsForUserForMonthRequest.RequestReference) .Returns(validGetBillsForUserForMonthResponse); assembler.NewGetBillsForUserResponse( Arg.Any <List <BillDataModel> >(), validGetBillsForUserRequest.RequestReference) .Returns(validGetBillsForUserResponse); assembler.NewDeleteBillResponse(true, validDeleteBillRequest.RequestReference) .Returns(validDeleteBillResponse); assembler.NewGetBillResponse(validBillDataModel, validGetBillRequest.RequestReference) .Returns(validGetBillResponse); errorHelper = Substitute.For <IErrorHelper>(); errorHelper.Create(Arg.Any <Exception>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>()) .Returns(new ResponseErrorWrapper()); errorHelper.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>()) .Returns(new ResponseErrorWrapper()); orchestrator = new BillOrchestrator(assembler, repository, dataTransformer, errorHelper); }