public async Task <string> Create([FromBody] LeaseCreateViewModel model) { try { var lease = mapper.Map <Lease>(model); return(await leaseRepository.Create(lease)); } catch (Exception ex) { throw new Exception($"Error POSTing lease: {ex.Message}"); } }
public ActionResult Create(LeaseCreateViewModel model) { if (ModelState.IsValid) { var result = Service.CreateLease(model.ToServiceModel(), ((OwnerModel)Session["SelectedAccount"]).Id, User.Identity.Name); if (result) { return(RedirectToAction("Details", "Properties", new { pId = model.PropertyId })); } ModelState.AddModelError("", "Request could not be completed."); } OnCreate(); return(View(model)); }
public ActionResult Create(int aId) { var leaseApplication = Service.GetLeaseApplicationById(aId, ((OwnerModel)Session["SelectedAccount"]).Id, User.Identity.Name); var newLease = new LeaseCreateViewModel { PropertyId = leaseApplication.PropertyId, PropertyAddress = leaseApplication.PropertyAddress, LeaseApplicationId = aId, Duration = leaseApplication.Duration, MonthlyRent = leaseApplication.MonthlyRent, TenantFullName = leaseApplication.TenantFullName, StartDate = DateTime.Now.AddDays(15), EndDate = DateTime.Now.AddDays(3).AddMonths((int)leaseApplication.Duration), TenantId = leaseApplication.TenantId, LeaseStatusId = 2, LeaseStatus = "Active", InitialDeposit = 3 * leaseApplication.MonthlyRent, InitialDepositDescription = "Includes first month, last month and security deposit." }; OnCreate(); return(View(newLease)); }
public static LeaseModel ToServiceModel(this LeaseCreateViewModel model) { return(Mapper.Map <LeaseCreateViewModel, LeaseModel>(model)); }