public bool AddBill_S(Bill bill) { if (_repository.AddBill(bill)) { return(true); } return(false); }
/// <summary> /// Adds a bill. /// </summary> /// <param name="request">The request.</param> /// <returns> /// The response object. /// </returns> public async Task <AddBillResponse> AddBill(AddBillRequest request) { return(await Orchestrate(async delegate { var dataModel = assembler.NewBillDataModel(request.Bill); var bill = await repository.AddBill(dataModel); return assembler.NewAddBillResponse(bill, request.RequestReference); }, request)); }
public IActionResult AddBill(Bill billToAdd) { var wasAddSuccessful = _billRepository.AddBill(billToAdd, billToAdd.BillProducts.ToList()); if (wasAddSuccessful) { return(Ok()); } return(Forbid()); }
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); }
public IActionResult Create(int[] products) { Customer c = _cust.GetCustomer((int)HttpContext.Session.GetInt32("CID")); Owner owner = DataManagement.ManageOwner.GetOwner(); float TotalAmount = 0; float TotalWeight = 0; List <Product> ps = new List <Product>(); foreach (var product in products) { Product p = _prod.GetProduct(product); ps.Add(p); _prod.Delete(p.ProductId); TotalWeight = p.Weight; TotalAmount += p.LabourCharge * p.Weight; } TotalAmount += TotalWeight * ((owner.GoldPrice) / 10); bill = new Bill { BillDate = DateTime.Today, CurrentGoldPrice = owner.GoldPrice, TotalWeight = TotalWeight, TotalAmount = TotalAmount }; _bill.AddBill(bill); c.Bills = new List <Bill>(); c.Bills.Add(bill); _cust.Update(c); All a = new All { customer = c, owner = owner, bill = bill, products = ps }; DataManagement.ManageBill.CreateBill(new BillDetails { bill = bill, customer = c, products = ps }); return(View("Bill", a)); }
public IActionResult PostBill([FromBody] BillForOperationsDto bill, int accountId = -1) { if (bill is null) { return(BadRequest()); } if (!_arepo.AuthorizeUser(accountId, Permission.AddBill)) { return(Unauthorized()); } var(isValid, errs) = bill.Validate(); if (!isValid) { return(BadRequest(errs)); } if (!_srepo.StaffExists(bill.StaffId)) { return(NotFound()); } for (var i = 0; i < bill.BillDetails.Count(); i++) { var bd = bill.BillDetails.ElementAt(i); var(isBdValid, errors) = bd.Validate(i); if (!isBdValid) { return(BadRequest(errors)); } if (!_prepo.ProductDetailExists(bd.BarCode)) { return(NotFound()); } } var billToAdd = Mapper.Map <Bill>(bill); return(_repo.AddBill(billToAdd) ? new StatusCodeResult(StatusCodes.Status201Created) : new StatusCodeResult(StatusCodes.Status500InternalServerError)); }
public void GenerateNextMonthsBills(int houseId) { // Only works for first household var bills = _billRepository.GetAllBasicBillDetails(new Pagination { Page = 0, ResultsPerPage = int.MaxValue }, houseId); var recurringBills = bills.Where(bill => bill.RecurringType == RecurringType.Monthly); foreach (var recurringBill in recurringBills) { if (recurringBill.FullDateDue > DateTime.Today) { continue; } var billUpdateRequest = new UpdateBill { Id = recurringBill.Id, RecurringType = RecurringType.None }; _billRepository.UpdateBill(billUpdateRequest); var addBillRequest = new AddBill { Due = recurringBill.FullDateDue.AddMonths(1), RecurringType = RecurringType.Monthly, Name = recurringBill.Name, PeopleIds = recurringBill.People.Select(person => person.Id).ToList(), TotalAmount = recurringBill.TotalAmount, HouseId = houseId }; _billRepository.AddBill(addBillRequest); } }
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); }
public IActionResult AddBill([FromBody] Bill bill, [FromRoute] List <Sale> sale) { var newbill = _billRepository.AddBill(bill, sale); return(Ok(newbill)); }