public ActionResult Create(LeaseTermViewModel model, int pId = -1) { if (ModelState.IsValid) { if (pId > 0) { model.PropertyId = pId; } LeaseTermModel serviceModel = new LeaseTermModel { PropertyId = model.PropertyId, Description = model.Description, Duration = model.Duration, MonthlyRent = model.MonthlyRent, IsActive = true }; var result = this.Service.CreateLeaseTerm((((OwnerModel)Session["SelectedAccount"]).Id), serviceModel); if (result) { return(RedirectToAction("Details", "Properties", new { pId = model.PropertyId })); } ModelState.AddModelError("", "The lease term could not be created. Check if you have the right permissions to perfomr this action and if the selected property exists."); } OnCreate(); return(View(model)); }
public bool CreateLeaseTerm(int ownerId, LeaseTermModel term) { var prop = Entities.Properties.Find(term.PropertyId); if (prop != null && prop.OwnerId == ownerId) { var termDb = new LeaseTerm { PropertyId = term.PropertyId, Description = term.Description, Duration = term.Duration, MonthlyRent = term.MonthlyRent, IsActive = term.IsActive }; Entities.LeaseTerms.Add(termDb); Entities.SaveChanges(); return(true); } return(false); }
public static LeaseTermViewModel ToViewModel(this LeaseTermModel model) { return(Mapper.Map <LeaseTermModel, LeaseTermViewModel>(model)); }