public async Task <IActionResult> PutBills(int id, ApiBills bills) { if (id != bills.BillId) { return(BadRequest("Bill does not exist.")); } var resource = new CoreBills { BillId = bills.BillId, BillLate = bills.BillLate, BillName = bills.BillName, BillPrice = bills.BillPrice, DueDate = bills.DueDate, User = await _userRepo.GetUserById(bills.UserId) }; try { await _repo.UpdateBillAsync(resource); } catch (DbUpdateConcurrencyException) { if (!await _repo.BillExistAsync(id)) { return(NotFound("Bill not found")); } else { throw; } } return(Ok("Bill updated!")); }
public async Task UpdateBillAsync(CoreBills bill) { var newBill = Mapper.MapBills(bill); _context.Entry(newBill).State = EntityState.Modified; await Save(); }
public async Task <CoreBills> AddBillAsync(CoreBills bill) { var newBill = Mapper.MapBills(bill); _context.Bills.Add(newBill); await Save(); return(Mapper.MapBills(newBill)); }
/* ************************ * * * * * Bills * * * * * ************************ */ public static Bills MapBills(CoreBills bills) { return(new Bills { BillId = bills.BillId, BillLate = bills.BillLate, BillName = bills.BillName, BillPrice = bills.BillPrice, DueDate = bills.DueDate, UserId = bills.User.UserId }); }
/* ************************ * * * * * Bills * * * * * ************************ */ public static ApiBills MapBills(CoreBills bills) { return(new ApiBills { BillId = bills.BillId, BillLate = bills.BillLate, BillName = bills.BillName, BillPrice = bills.BillPrice, DueDate = bills.DueDate, UserId = bills.User.UserId, UserFirstName = bills.User.FirstName, UserLastName = bills.User.LastName }); }
public void MapBills_CoreBills() { var mapper = this.CreateMapper(); CoreBills bills = new CoreBills { BillDate = new DateTime(), Cost = 1, Id = 1, Location = "location", PurchaseName = "purchase", Quantity = 1, UserId = 1, }; var result = Mapper.MapBills( bills); Assert.True(true); }
public void MapBillsApi_StateUnderTest_ExpectedBehavior() { var apiMapper = this.CreateApiMapper(); CoreBills bills = new CoreBills { BillDate = new DateTime(), Cost = 1, Id = 1, Location = "location", PurchaseName = "purchase", Quantity = 1, UserId = 1, }; var result = ApiMapper.MapBillsApi( bills); Assert.True(true); this.mockRepository.VerifyAll(); }
public void AddBills() { var listOfBills = new CoreBills(); listOfBills = new CoreBills { Id = 1, UserId = 2, PurchaseName = "Mock", Quantity = 2, Cost = 3, BillDate = new DateTime(), Location = "Mock Location", }; var a = Mapper.MapBills(listOfBills); Mock <IBillsRepository> mockBillRepository = new Mock <IBillsRepository>(); mockBillRepository.Setup(x => x.AddBillAsync(listOfBills)).Verifiable(); var billController = new BillsController(mockBillRepository.Object); billController.Should().NotBeNull(); }
public async Task <ActionResult> PostBills(ApiBills bills) { try { var resource = new CoreBills { BillId = bills.BillId, BillLate = bills.BillLate, BillName = bills.BillName, BillPrice = bills.BillPrice, DueDate = bills.DueDate, User = await _userRepo.GetUserById(bills.UserId) }; await _repo.AddBillAsync(resource); return(Ok("Bill had been added!")); } catch (Exception e) { return(BadRequest($"Something went wrong. {e.Message}")); } }
public void TestBills() { var listOfBills = new CoreBills(); listOfBills = new CoreBills { Id = 1, UserId = 2, PurchaseName = "Mock", Quantity = 2, Cost = 3, BillDate = new DateTime(), Location = "Mock Location", }; var bills = new Bills { Id = 1, UserId = 2, PurchaseName = "Mock", Quantity = 2, Cost = 3, BillDate = new DateTime(), Location = "Mock Location", }; var a = Mapper.MapBills(listOfBills); Mock <IBillsRepository> mockBillRepository = new Mock <IBillsRepository>(); mockBillRepository.Setup(x => x.GetBillsAsync(null)).Verifiable(); var billController = new BillsController(mockBillRepository.Object); var bill = billController.GetBills(); var bill2 = billController.GetUserBills(1); var bill3 = billController.PostBills(bills); var bill4 = billController.PutBills(1, bills); var bill5 = billController.DeleteBills(1); billController.Should().NotBeNull(); }