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, Lessees = _combosHelper.GetComboLessees(), Price = property.Price, StartDate = DateTime.Today, EndDate = DateTime.Today.AddYears(1) }; return(View(model)); }
public async Task <IActionResult> AddContract(int?id) { if (id == null)//Valida si el id de la propiedad no es nulo { return(NotFound()); } //mediante una consulta relacionada busca el objeto owner // usando el id de la propiedad Property property = await _dataContext.Properties .Include(p => p.Owner) .FirstOrDefaultAsync(p => p.Id == id.Value); if (property == null) { return(NotFound()); } ContractViewModel model = new ContractViewModel { //gracias a la consulta relacionada ya podemos completar el modelo //sacando los id que necesitamos enviarle OwnerId = property.Owner.Id, PropertyId = property.Id, //Es la funcion que se debe armar en el combosHelper para tener //el combo box con los arrendatarios Lessees = _combosHelper.GetComboLessees(), Price = property.Price, //dejamos por defecto el precio inicial StartDate = DateTime.Today, //la fecha inicial será la fecha del sistema EndDate = DateTime.Today.AddYears(1) //la fecha final le sumamos 1 año }; return(View(model)); }
public async Task <IActionResult> AddProperty(PropertyViewModel model) { if (ModelState.IsValid) { var property = await _converterHelper.ToPropertyAsync(model, true); _dataContext.Properties.Add(property); //se va a vase de datos await _dataContext.SaveChangesAsync(); //aqui estamos redireccionado return(RedirectToAction($"Details/{model.OwnerId}")); } //esto es por si el combo box se marca luego no sale el dato model.PropertyTypes = _combosHelper.GetComboLessees(); return(View(model)); }
public ContractViewModel ToContractViewModel(Contract contract) { return(new ContractViewModel { EndDate = contract.EndDate, IsActive = contract.IsActive, LesseeId = contract.Lessee.Id, OwnerId = contract.Owner.Id, Price = contract.Price, Remarks = contract.Remarks, StartDate = contract.StartDate, Id = contract.Id, Lessees = _combosHelper.GetComboLessees(), PropertyId = contract.Property.Id }); }
public ContractViewModel ToContractViewModel(Contract contract) { return(new ContractViewModel { EndDate = contract.EndDate.ToUniversalTime(), Id = contract.Id, IsActive = contract.IsActive, Lessee = contract.Lessee, Owner = contract.Owner, Price = contract.Price, Property = contract.Property, Remarks = contract.Remarks, StartDate = contract.StartDateLocal, LesseeId = contract.Lessee.Id, Lessees = _combosHelper.GetComboLessees(), OwnerId = contract.Owner.Id, PropertyId = contract.Property.Id }); }
public ContractViewModel ToContractViewModel(Contract contract) { return(new ContractViewModel { //esto se aguarda con hora de londres ToUniversalTime() hora universal EndDate = contract.EndDateLocal, //estamos creando un operador ternario si es nuevo se carga 0 si no es nuevo le cargas lo que trae el contracto Id = contract.Id, IsActive = contract.IsActive, Lessee = contract.Lessee, Owner = contract.Owner, Price = contract.Price, Property = contract.Property, Remarks = contract.Remarks, StartDate = contract.StartDateLocal, LesseeId = contract.Lessee.Id, Lessees = _combosHelper.GetComboLessees(), OwnerId = contract.Owner.Id, PropertyId = contract.Property.Id }); }