public ActionResult UpdateConsortium(ConsortiumViewModel consortium) { var nConsortium = Mapper.Map <ConsortiumRequest>(consortium); this.ConsortiumService.UpdateConsortium(nConsortium); return(View()); }
public ActionResult CreateConsortium() { var administrations = this.AdministrationService.GetAll().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name }); var ownerships = this.OwnershipService.GetAll().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Address.Street + " " + x.Address.Number.ToString() }); var commonDataItems = this.CommonDataService.GetItems().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Description }); var provinces = this.CountryService .GetAllProvinces(int.Parse(ConfigurationManager.AppSettings["default_country_id"])); var provincesList = provinces.Select(x => new SelectListItem() { Value = x.Description, Text = x.Description }); var cities = provinces.FirstOrDefault().Cities; var citiesList = cities.Select(x => new SelectListItem() { Value = x.Description, Text = x.Description }); var viewModel = new ConsortiumViewModel() { Administrations = new SelectList(administrations, "Value", "Text"), Ownerships = new SelectList(ownerships, "Value", "Text"), CommonDataItems = new SelectList(commonDataItems, "Value", "Text"), Provinces = provincesList, Cities = citiesList }; viewModel.Ownership = new OwnershipViewModel() { Address = new AddressViewModel() { Province = "Buenos Aires", City = "Ciudad Autónoma de Buenos Aires" } }; return(View(viewModel)); }
public ActionResult CreateUpdateConsortium(ConsortiumViewModel consortium) { var nConsortium = Mapper.Map <ConsortiumRequest>(consortium); try { var result = false; if (nConsortium.Id == 0) { var nOwnershp = Mapper.Map <Ownership>(consortium.Ownership); var nresult = this.OwnershipService.CreateOwnership(nOwnershp); if (nresult.Id > 0) { this.UploadMultimedia(nresult.Id); nConsortium.OwnershipId = nresult.Id; nConsortium.AdministrationId = 1; result = this.ConsortiumService.CreateConsortium(nConsortium); if (result) { foreach (var data in consortium.Ownership.CommonData) { var cdataRequest = new CommonDataRequest() { CommonDataItemId = data.Item.Id, Have = data.Have, OwnershipId = nConsortium.OwnershipId }; this.CommonDataService.CreateCommonData(cdataRequest); } } } } else { var oOwnership = this.OwnershipService.GetOwnership(consortium.Ownership.Id); this.UploadMultimedia(consortium.Ownership.Id); var nOwnership = new Ownership() { Address = new Address() { City = consortium.Ownership.Address.City, Number = consortium.Ownership.Address.Number, PostalCode = consortium.Ownership.Address.PostalCode, Province = consortium.Ownership.Address.Province, Street = consortium.Ownership.Address.Street }, Category = consortium.Ownership.Category, FunctionalUnits = oOwnership.FunctionalUnits, Id = oOwnership.Id }; result = this.OwnershipService.UpdateOwnership(nOwnership); if (result) { result = this.ConsortiumService.UpdateConsortium(nConsortium); if (result) { foreach (var data in consortium.Ownership.CommonData) { if (data.Id == 0) { var cdataRequest = new CommonDataRequest() { CommonDataItemId = data.Item.Id, Have = data.Have, OwnershipId = consortium.Ownership.Id }; this.CommonDataService.CreateCommonData(cdataRequest); } else { var cdataRequest = new CommonDataRequest() { Id = data.Id, CommonDataItemId = data.Item.Id, Have = data.Have, OwnershipId = consortium.Ownership.Id }; this.CommonDataService.UpdateCommonData(cdataRequest); } } } } } if (result) { return(Redirect("/Consortium/Index")); } else { return(View("../Shared/Error")); } } catch (Exception ex) { return(View("../Shared/Error")); } }