public async Task <IActionResult> RentBookCopy() { //1- Check if this book is available //if yes: just add a new book copy //if not: create a new book then add a new book copy in the db var userEmail = HttpContext.Items["Email"] as string; var user = await _context.Users.FirstAsync(x => x.Email == userEmail); var userId = user.UserId ?? default(int); var cartItems = await _context.Carts.Where(x => x.UserId == userId).ToListAsync(); foreach (var cartItem in cartItems) { var rentalContract = new RentalContract(userId, DateTime.Now.AddDays(21)); _context.RentalContracts.Add(rentalContract); _context.SaveChanges(); int id = rentalContract.ContractID ?? default(int); var lentBook = new Contains(id, cartItem.BookCopyId); _context.Contain.Add(lentBook); _context.SaveChanges(); } foreach (var cartItem in cartItems) { _context.Carts.Remove(cartItem); _context.SaveChanges(); } return(Ok()); }
//public void AddRentedUnit(RentedUnit entity) //{ // var cu = (RentalAccount)_contractUnitRepsoitory.GetById(entity.CustomerAccountId); // entity.Stock = _stockService.GetStock(entity.StockId); // cu.AddRentedUnitAndUpdateContract(entity); // _contractUnitRepsoitory.Update(cu); //} //public RentedUnit GetRentedUnit(int id) //{ // return _rentedUnitRepository.GetById(id); //} //public void UpdateRentedUnit(RentedUnit ru) //{ // var cu = (RentalAccount)_contractUnitRepsoitory.GetById(ru.CustomerAccountId); // cu.UpdateRentedUnitAndUpdateContract(ru); // _contractUnitRepsoitory.Update(cu); //} //public void DeleteRentedUnitStock(RentedUnit rentedUnit) //{ // var cu = (RentalAccount)_contractUnitRepsoitory.GetById(rentedUnit.CustomerAccountId); // cu.RemoveRentedUnit(rentedUnit); // _contractUnitRepsoitory.Update(cu); //} public void UpdateRentalContract(RentalContract rc) { //var cur = _contractUnitRepsoitory.GetById(rc.CustomerAccountId) as ContractUnitRental; //TODO Review. rc.ChangePaymentPeriod(_paymentPeriodRepository.GetById(rc.PaymentPeriodId)); //cur.RentedContract = rc; //_contractUnitRepsoitory.Update(cur); }
public async Task <IActionResult> Create([FromBody] RentalContract contract) { if (contract == null) { return(BadRequest($"{nameof(contract)} must not be null!")); } try { if (contract.ReservationId != 0) { var reservation = await _reservationsRepository.GetAsync(contract.ReservationId); reservation.State = ReservationState.Contracted; await _reservationsRepository.UpdateAsync(reservation); } var obj = await _contractsRepository.AddAsync(contract); return(CreatedAtRoute("GetContract", new { id = obj.Id }, obj)); } catch (Exception e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e)); } }
public void UpdateContractInvoices(RentalContract contract) { var property = _contractService.GetProperty(contract); var invoiceList = ListByContract(property.Owner, contract.Id); var endDate = contract.EndDate != null ? contract.EndDate : DateTime.Now; var beginDate = contract.BeginDate; // var firstPaymentDOM = beginDate.Day > contract.PaymentDayOfMonth }
public RentalContract Create(Property property, RentalContract contract) { contract.Property = property.Id; property.Contracts.Add(contract); var update = Builders <Property> .Update.Set("contracts", property.Contracts); _properties.FindOneAndUpdate <Property>(prop => prop.Id == property.Id, update); return(contract); }
// GET: RentalContracts/Delete/5 public ActionResult Delete(int id) { RentalContract contract = null; if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (SqlConnection scRentManagement = new SqlConnection(System.Configuration. ConfigurationManager. ConnectionStrings["csApartmentsRentalManagement"]. ConnectionString)) { SqlCommand cmdRentalContracts = new SqlCommand("SELECT RentalContractID, ContractNumber, " + " EmployeeID, ContractDate, " + " FirstName, LastName, " + " MaritalStatus, NumberOfChildren, " + " ApartmentID, RentStartDate " + "FROM Management.RentalContracts " + "WHERE RentalContractID = " + id + ";", scRentManagement); scRentManagement.Open(); SqlDataAdapter sdaRentalContracts = new SqlDataAdapter(cmdRentalContracts); DataSet dsRentalContracts = new DataSet("rental-contracts"); sdaRentalContracts.Fill(dsRentalContracts); if (dsRentalContracts.Tables[0].Rows.Count > 0) { contract = new RentalContract() { RentalContractID = int.Parse(dsRentalContracts.Tables[0].Rows[0][0].ToString()), ContractNumber = int.Parse(dsRentalContracts.Tables[0].Rows[0][1].ToString()), EmployeeID = int.Parse(dsRentalContracts.Tables[0].Rows[0][2].ToString()), ContractDate = DateTime.Parse(dsRentalContracts.Tables[0].Rows[0][3].ToString()), FirstName = dsRentalContracts.Tables[0].Rows[0][4].ToString(), LastName = dsRentalContracts.Tables[0].Rows[0][5].ToString(), MaritalStatus = dsRentalContracts.Tables[0].Rows[0][6].ToString(), NumberOfChildren = int.Parse(dsRentalContracts.Tables[0].Rows[0][7].ToString()), ApartmentID = int.Parse(dsRentalContracts.Tables[0].Rows[0][8].ToString()), RentStartDate = DateTime.Parse(dsRentalContracts.Tables[0].Rows[0][9].ToString()) }; } } return(contract == null?HttpNotFound() : (ActionResult)View(contract)); }
// GET: RentalContracts/Edit/5 public ActionResult Edit(int id) { if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentalContract contract = objects.FindRentalContract(id); if (contract == null) { return(HttpNotFound()); } List <SelectListItem> maritals = new List <SelectListItem> { new SelectListItem() { Text = "Single", Value = "Single", Selected = (contract.MaritalStatus == "Single") }, new SelectListItem() { Text = "Widdow", Value = "Widdow", Selected = (contract.MaritalStatus == "Widdow") }, new SelectListItem() { Text = "Married", Value = "Married", Selected = (contract.MaritalStatus == "Married") }, new SelectListItem() { Text = "Unknown", Value = "Unknown", Selected = (contract.MaritalStatus == "Unknown") }, new SelectListItem() { Text = "Divorced", Value = "Divorced", Selected = (contract.MaritalStatus == "Divorced") }, new SelectListItem() { Text = "Separated", Value = "Separated", Selected = (contract.MaritalStatus == "Separated") } }; ViewBag.MaritalStatus = maritals; ViewBag.EmployeeID = new SelectList(objects.GetEmployees(), "EmployeeID", "Identification", contract.EmployeeID); ViewBag.ApartmentID = new SelectList(objects.GetApartments(), "ApartmentID", "Residence", contract.ApartmentID); return(View(contract)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } RentalContract = await _context.RentalContract.FirstOrDefaultAsync(m => m.RentalContractId == id); if (RentalContract == null) { return(NotFound()); } return(Page()); }
public async Task <bool> SaveContractSubmission(byte[] contractSubmission, DateTime currentDate, string fileName) { var contract = new RentalContract { DateSubmitted = currentDate, ContractSubmission = contractSubmission, Name = fileName }; this.db.Contracts.Add(contract); await this.db.SaveChangesAsync(); return(true); }
// GET: RentalContracts/Details/5 public ActionResult Details(int id) { if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentalContract contract = objects.FindRentalContract(id); if (contract == null) { return(HttpNotFound()); } return(View(contract)); }
public void AddRentedUnitAndUpdateContract(RentedUnit rentedUnit) { RentedUnits = RentedUnits ?? new List <RentedUnit>(); RentedUnits.Add(rentedUnit); if (GetActiveRentalContract() == null) { RentedContract = new RentalContract(); } RentedContract.StartDate = rentedUnit.RentedDate; RentedContract.ExpiryDate = null; RentedContract.Charge = MonthlyCharge; RentedContract.PaymentPeriodId = 1; RentedContract.NoOfUnits = RentedUnits.Count; //RentedContract.AddAdjustmentPostForAddedRentedUnit(rentedUnit); rentedUnit.Stock.ProductLifeCycleId = (int)ProductLifeCycleStatus.Rented; rentedUnit.Stock.CustomerAccountId = this.CustomerAccountId; }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } RentalContract = await _context.RentalContract.FindAsync(id); if (RentalContract != null) { _context.RentalContract.Remove(RentalContract); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public RentalContract Update(Property property, string contractId, RentalContract contract) { var index = property.Contracts.FindIndex(rc => rc.Id == contractId); if (index == -1) { throw new Exception("update_property_not_found"); } property.Contracts[index] = contract; property.Contracts[index].Property = property.Id; var update = Builders <Property> .Update.Set("contracts", property.Contracts); _properties.FindOneAndUpdate <Property>(prop => prop.Id == property.Id, update); return(property.Contracts[index]); }
public ActionResult Delete([FromBody] DeleteContractFields deleteFields) { var user = (User)Request.HttpContext.Items["user"]; RentalContract contract = _contractService.Get(user.Id, deleteFields.contractId); if (contract == null) { return(NotFound()); } if (!_contractService.Remove(user.Id, deleteFields.propertyId, contract.Id)) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> Update([FromBody] RentalContract contract) { try { var exists = await _contractsRepository.GetAsync(contract.Id) != null; if (!exists) { return(NotFound($"No Object found with ID {contract.Id}")); } await _contractsRepository.UpdateAsync(contract); return(Ok()); } catch (Exception e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e)); } }
public void SubmitRentalContract(RentalContract rentalContract) { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { NetNamedPipeBinding netNamedPipeBinding; netNamedPipeBinding = new NetNamedPipeBinding(); netNamedPipeBinding.TransactionFlow = true; CustomerInterface.ICustomer customerServiceChannel; customerServiceChannel = ChannelFactory <CustomerInterface.ICustomer> .CreateChannel(netNamedPipeBinding, new EndpointAddress("net.pipe://localhost/customerservice")); int newCustomerID; newCustomerID = customerServiceChannel.RegisterCustomer(rentalContract.Customer); RentalInterface.IRental rentalServiceChannel; rentalServiceChannel = ChannelFactory <RentalInterface.IRental> .CreateChannel(netNamedPipeBinding, new EndpointAddress("net.piped://localhost/rentalservice")); rentalServiceChannel.RegisterCarRental(rentalContract.RentalRegistration); scope.Complete(); } }
public void SubmitRentalContract(RentalContract rentalContract) { Console.WriteLine("SubmitRentalContract"); Console.WriteLine(rentalContract.Company); Console.WriteLine(rentalContract.CompanyReferenceID); Console.WriteLine(rentalContract.RentalRegistration.PickUpLocation); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { try { NetNamedPipeBinding netNamedPipeBinding; netNamedPipeBinding = new NetNamedPipeBinding(); netNamedPipeBinding.TransactionFlow = true; CustomerInterface.ICustomer customerServiceChannel; customerServiceChannel = ChannelFactory <CustomerInterface.ICustomer> .CreateChannel(netNamedPipeBinding, new EndpointAddress("net.pipe://localhost/customerservice")); int newCustomerID; newCustomerID = customerServiceChannel.RegisterCustomer(rentalContract.Customer); Console.WriteLine("CustomerRegistered"); rentalContract.RentalRegistration.CustomerID = newCustomerID; //throw new DivideByZeroException(); RentalInterface.IRental rentalServiceChannel; rentalServiceChannel = ChannelFactory <RentalInterface.IRental> .CreateChannel(netNamedPipeBinding, new EndpointAddress("net.pipe://localhost/rentalservice")); rentalServiceChannel.RegisterCarRental(rentalContract.RentalRegistration); Console.WriteLine("CarRentalRegistered"); scope.Complete(); Console.WriteLine("-- Scope Complete --"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public ActionResult <RentalContract> Update(UpdateContractFields updateContract) { var user = (User)Request.HttpContext.Items["user"]; Property property = _propertyService.Get(updateContract.propertyId, user.Id); if (property == null) { return(NotFound()); } RentalContract contract = property.Contracts.Find(ct => ct.Id == updateContract.contractId); if (contract == null) { return(NotFound()); } updateContract.contract.Id = contract.Id; updateContract.contract.Property = property.Id; _contractService.Update(property, updateContract.contract.Id, updateContract.contract); return(updateContract.contract); }
public async Task InitDemoDataAsync() { var brands = await BrandRepository.GetAllAsync(); if (brands.Any()) { return; // already initialized } var brandA = new CarBrand { Title = "Audi" }; var brandB = new CarBrand { Title = "BMW" }; var brandC = new CarBrand { Title = "Fiat" }; brandA = await BrandRepository.AddAsync(brandA); brandB = await BrandRepository.AddAsync(brandB); brandC = await BrandRepository.AddAsync(brandC); var classA = new CarClass { Title = "Cheap", Cost = 102.20M }; var classB = new CarClass { Title = "Midlevel", Cost = 180.50M }; var classC = new CarClass { Title = "Highend", Cost = 250.99M }; classA = await ClassRepository.AddAsync(classA); classB = await ClassRepository.AddAsync(classB); classC = await ClassRepository.AddAsync(classC); var typeA = new CarType { Title = "PKW" }; var typeB = new CarType { Title = "Limousine" }; var typeC = new CarType { Title = "Coupé" }; typeA = await TypeRepository.AddAsync(typeA); typeB = await TypeRepository.AddAsync(typeB); typeC = await TypeRepository.AddAsync(typeC); var customerA = new Customer { FirstName = "Peter", LastName = "Müller", Address = "Mordorweg 4, 8355 Gondor", EMail = "*****@*****.**", PhoneNumber = "79 546 65 65" }; var customerB = new Customer { FirstName = "Maria", LastName = "Meier", Address = "Rohangasse 23, 5564 Auenland", EMail = "*****@*****.**", PhoneNumber = "76 215 54 64" }; var customerC = new Customer { FirstName = "Bruno", LastName = "Gander", Address = "Isengardweg 3, 5445 Helmsklamm", EMail = "*****@*****.**", PhoneNumber = "76 651 12 35" }; customerA = await CustomerRepository.AddAsync(customerA); customerB = await CustomerRepository.AddAsync(customerB); customerC = await CustomerRepository.AddAsync(customerC); var carA = new Car { BrandId = brandA.Id, ClassId = classA.Id, HorsePower = 112, Kilometers = 216535, RegistrationYear = 2000, TypeId = typeA.Id }; var carB = new Car { BrandId = brandB.Id, ClassId = classB.Id, HorsePower = 212, Kilometers = 116535, RegistrationYear = 2010, TypeId = typeB.Id }; var carC = new Car { BrandId = brandC.Id, ClassId = classC.Id, HorsePower = 312, Kilometers = 16535, RegistrationYear = 2018, TypeId = typeC.Id }; carA = await CarRepository.AddAsync(carA); carB = await CarRepository.AddAsync(carB); carC = await CarRepository.AddAsync(carC); var reservationA = new Reservation { CarId = carA.Id, CustomerId = customerA.Id, Days = 12, RentalDate = DateTime.Now.AddDays(12), ReservationDate = DateTime.Now, State = ReservationState.Pending }; var reservationB = new Reservation { CustomerId = customerB.Id, CarId = carB.Id, Days = 2, RentalDate = DateTime.Now.AddDays(1), ReservationDate = DateTime.Now.AddDays(-3), State = ReservationState.Reserved }; var reservationC = new Reservation { CustomerId = customerC.Id, CarId = carC.Id, Days = 42, RentalDate = DateTime.Now.AddDays(-2), ReservationDate = DateTime.Now.AddDays(-8), State = ReservationState.Contracted }; await ReservationRepository.AddAsync(reservationA); await ReservationRepository.AddAsync(reservationB); reservationC = await ReservationRepository.AddAsync(reservationC); var contractA = new RentalContract { CarId = carC.Id, CustomerId = customerC.Id, Days = 42, RentalDate = DateTime.Now.AddDays(-2), ReservationId = reservationC.Id, TotalCosts = classC.Cost * 42 }; await ContractRepository.AddAsync(contractA); }
public ActionResult Edit(int id, FormCollection collection) { try { // TODO: Add update logic here if (ModelState.IsValid) { using (SqlConnection scApartmentsManagement = new SqlConnection(System. Configuration. ConfigurationManager. ConnectionStrings["csApartmentsRentalManagement"]. ConnectionString)) { string strUpdate = "UPDATE Management.RentalContracts " + "SET ContractNumber = " + collection["ContractNumber"] + ", " + " EmployeeID = " + collection["EmployeeID"] + ", " + " FirstName = N'" + collection["FirstName"] + "', " + " LastName = N'" + collection["LastName"] + "', " + " MaritalStatus = N'" + collection["MaritalStatus"] + "', " + " NumberOfChildren = " + collection["NumberOfChildren"] + ", " + " ApartmentID = " + collection["ApartmentID"] + " " + "WHERE RentalContractID = " + id + ";"; if (DateTime.Parse(collection["ContractDate"]) != new DateTime(1900, 1, 1)) { strUpdate += "UPDATE Management.RentalContracts " + "SET ContractDate = N'" + collection["ContractDate"] + "' " + "WHERE RentalContractID = " + id + ";"; } if (DateTime.Parse(collection["RentStartDate"]) != new DateTime(1900, 1, 1)) { strUpdate += "UPDATE Management.RentalContracts " + "SET RentStartDate = N'" + collection["RentStartDate"] + "' " + "WHERE RentalContractID = " + id + ";"; } SqlCommand cmdRentalContracts = new SqlCommand(strUpdate, scApartmentsManagement); scApartmentsManagement.Open(); cmdRentalContracts.ExecuteNonQuery(); } /* Change the status of the newly selected apartment (the apartment that has just been applied to the contract), * to Occupied (from whatever was its status). */ using (SqlConnection scRentManagement = new SqlConnection(System.Configuration. ConfigurationManager. ConnectionStrings["csApartmentsRentalManagement"]. ConnectionString)) { SqlCommand cmdApartments = new SqlCommand("UPDATE Management.Apartments " + "SET OccupancyStatus = N'Occupied' " + "WHERE ApartmentID = " + collection["ApartmentID"] + ";", scRentManagement); scRentManagement.Open(); cmdApartments.ExecuteNonQuery(); } return(RedirectToAction("Index")); } RentalContract contract = objects.FindRentalContract(id); List <SelectListItem> maritals = new List <SelectListItem> { new SelectListItem() { Text = "Single", Value = "Single" }, new SelectListItem() { Text = "Widdow", Value = "Widdow" }, new SelectListItem() { Text = "Married", Value = "Married" }, new SelectListItem() { Text = "Unknown", Value = "Unknown" }, new SelectListItem() { Text = "Divorced", Value = "Divorced" }, new SelectListItem() { Text = "Separated", Value = "Separated" } }; ViewBag.MaritalStatus = maritals; ViewBag.EmployeeID = new SelectList(objects.GetEmployees(), "EmployeeID", "Identification", contract.EmployeeID); ViewBag.ApartmentID = new SelectList(objects.GetApartments(), "ApartmentID", "Residence", contract.ApartmentID); return(View(contract)); } catch { return(View()); } }
public async Task DeleteAsync(RentalContract obj) { _dbContext.RentalContracts.Remove(obj); await _dbContext.SaveChangesAsync(); }
public async Task AddAsync(RentalContract obj) { await _dbContext.RentalContracts.AddAsync(obj); await _dbContext.SaveChangesAsync(); }
public Property GetProperty(RentalContract contract) => _properties.Find((prop) => prop.Id == contract.Property).FirstOrDefault();