public ActionResult CreateFunctionalUnit(int id) { var consortium = this.ConsortiumService.GetConsortium(id); var owners = this.OwnersService.GetAll().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.User.Name + " " + x.User.Surname }); var renters = this.RenterService.GetAll().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.User.Name + " " + x.User.Surname }); var viewModel = new FunctionalUnitViewModel() { ConsortiumId = consortium.Id, Renters = new SelectList(renters, "Value", "Text"), Owners = new SelectList(owners, "Value", "Text") }; return(View(viewModel)); }
public ActionResult UpdateFunctionalUnit(FunctionalUnitViewModel unit) { var nunit = new FunctionalUnit(); nunit = Mapper.Map <FunctionalUnit>(unit); var entity = Mapper.Map <FunctionalUnitRequest>(nunit); this.FunctionalUnitService.UpdateFunctionalUnit(entity); return(View()); }
public ActionResult CreateUpdateFunctionalUnit(FunctionalUnitViewModel unit) { var consortium = this.ConsortiumService.GetConsortium(unit.ConsortiumId); var nunit = Mapper.Map <FunctionalUnit>(unit); nunit.Ownership = consortium.Ownership; Renter Renter = null; if (unit.RenterId != 0) { Renter = this.RenterService.GetRenter(unit.RenterId); } Owner Owner = null; if (unit.OwnerId != 0) { Owner = this.OwnersService.GetOwner(unit.OwnerId); } try { var result = false; var entity = Mapper.Map <FunctionalUnitRequest>(nunit); if (nunit.Id == 0) { var entidad = this.FunctionalUnitService.CreateFunctionalUnit(entity); if (entidad.Id > 0) { if (Renter != null) { var renterRequest = new RenterRequest() { Id = Renter.Id, FunctionalUnitId = entidad.Id, UserId = Renter.User.Id, PaymentTypeId = 1 }; this.RenterService.UpdateRenter(renterRequest); } if (Owner != null) { var ownerRequest = new OwnerRequest() { Id = Owner.Id, FunctionalUnitId = entidad.Id, UserId = Owner.User.Id }; this.OwnersService.UpdateOwner(ownerRequest); } result = true; } } else { result = this.FunctionalUnitService.UpdateFunctionalUnit(entity); if (Renter != null) { var renterRequest = new RenterRequest() { Id = Renter.Id, FunctionalUnitId = nunit.Id, UserId = Renter.User.Id, PaymentTypeId = Renter.PaymentTypeId }; this.RenterService.UpdateRenter(renterRequest); } if (Owner != null) { var ownerRequest = new OwnerRequest() { Id = Owner.Id, FunctionalUnitId = nunit.Id, UserId = Owner.User.Id }; this.OwnersService.UpdateOwner(ownerRequest); } result = true; } if (result) { return(Redirect(string.Format("/Consortium/Details/{0}", consortium.Id))); } else { return(View("../Shared/Error")); } } catch (Exception ex) { return(View("../Shared/Error")); } }