public ActionResult Create(CrudEventVm model, AddressForEventVm address) { try { model.Address = address; model.Event.Address = model.GetAddress(address); model.Event.Address.SetCoordinates(address.LatitudeString, address.LongitudeString); if (model.Event.Logo == null || model.LogoFile != null) { model.Event.Logo = FileUpload.GetBytes(model.LogoFile, "Logo"); } if (model.Event.Cover == null || model.CoverFile != null) { model.Event.Cover = FileUpload.GetBytes(model.CoverFile, "Capa"); } ModelState.Remove("Event.Logo"); ModelState.Remove("Event.Cover"); if (!ModelState.IsValid) { SetBiewBags(model); return(View(model).Error(ModelState)); } _db.Events.Add(model.Event); _db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { SetBiewBags(model); return(View(model).Error(ex.Message)); } }
private static CrudEventVm GetCrudVm(Event model) { var eventVm = new CrudEventVm { Event = model, Address = AddressForEventVm.GetAddress(model.Address) }; return(eventVm); }
public ActionResult Edit(CrudEventVm model, AddressForEventVm address) { try { model.Address = address; model.Event.Address = model.GetAddress(address); model.Event.Address.SetCoordinates(address.LatitudeString, address.LongitudeString); if (model.Event.Logo == null || model.LogoFile != null) { model.Event.Logo = FileUpload.GetBytes(model.LogoFile, "Logo"); } if (model.Event.Cover == null || model.CoverFile != null) { model.Event.Cover = FileUpload.GetBytes(model.CoverFile, "Capa"); } ModelState.Remove("Event.Logo"); ModelState.Remove("Event.Cover"); if (!ModelState.IsValid) { SetBiewBags(model); return(View(model).Error(ModelState)); } var oldCompany = _db.Events .Include(c => c.Address) //.Include(c => c.Contacts) .FirstOrDefault(x => x.EventId == model.Event.EventId); if (oldCompany == null) { return(RedirectToAction("Index").Success("Empresa atualizada com sucesso")); } // Update parent _db.Entry(oldCompany).CurrentValues.SetValues(model.Event); oldCompany.Address.UpdateAddress(model.Event.Address); _db.Entry(oldCompany.Address).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { SetBiewBags(model); return(View(model).Error(ex.Message)); } }
public ActionResult GetOrganizerAddress(Guid companyId) { var company = _db.Companies.Include(i => i.Address).FirstOrDefault(f => f.CompanyId == companyId); if (company?.Address == null) { return(PartialView("_FormAddress")); } var cities = _db.Cities.OrderBy(o => o.Name); ViewBag.Cities = new SelectList(cities, "CityId", "Name", company.Address?.CityId); company.Address.SetCoordinates(); return(PartialView("_Address", AddressForEventVm.GetAddress(company.Address))); }