public async Task <IActionResult> AddContract(int?id) { if (id == null) { return(NotFound()); } var property = await _dataContext.Properties .Include(p => p.Owner) .FirstOrDefaultAsync(p => p.Id == id.Value); if (property == null) { return(NotFound()); } var model = new ContractVIewModel { OwnerID = property.Owner.id, PropertyId = property.Id, Lesses = _combosHelper.GetComboLessees(), Price = property.Price, StartDate = DateTime.Today, EndDate = DateTime.Today.AddYears(1) }; return(View(model)); }
public async Task <IActionResult> AddContract(ContractVIewModel model) { if (ModelState.IsValid) { var contract = await _converterHelper.ToContractAsync(model, true); _dataContext.Contracts.Add(contract); await _dataContext.SaveChangesAsync(); return(RedirectToAction($"{nameof(DetailsProperty)}/{model.OwnerID}")); } return(NotFound()); }
public async Task <Contract> ToContractAsync(ContractVIewModel model, bool isNew) { return(new Contract { EndDate = model.EndDate.ToUniversalTime(), IsActive = model.IsActive, Lessee = await _dataContext.Lessees.FindAsync(model.LesseeId), Owner = await _dataContext.Owners.FindAsync(model.OwnerID), Price = model.Price, Property = await _dataContext.Properties.FindAsync(model.PropertyId), Remarks = model.Remarks, StartDate = model.StartDate.ToUniversalTime(), Id = isNew ? 0 : model.Id }); }