예제 #1
0
 public ActionResult Contacts(CrudEventVm eventContact)
 {
     UrlsContact();
     eventContact          = eventContact ?? new CrudEventVm();
     eventContact.Contacts = eventContact.Contacts ?? new List <Contact>();
     return(PartialView("_Contacts", eventContact.Contacts));
 }
예제 #2
0
        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));
            }
        }
예제 #3
0
        private static CrudEventVm GetCrudVm(Event model)
        {
            var eventVm = new CrudEventVm
            {
                Event   = model,
                Address = AddressForEventVm.GetAddress(model.Address)
            };

            return(eventVm);
        }
예제 #4
0
 public ActionResult AddContact(CrudEventVm eventContact)
 {
     eventContact.Contacts = eventContact.Contacts ?? new List <Contact>();
     eventContact.Contacts.Add(new Contact {
         Description = eventContact.Description, ContactType = eventContact.ContactType
     });
     eventContact.Description = string.Empty;
     eventContact.ContactType = 0;
     UrlsContact();
     return(PartialView("_Contacts", eventContact.Contacts));
 }
예제 #5
0
        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));
            }
        }
예제 #6
0
        private void SetBiewBags(CrudEventVm model)
        {
            string cityId;

            if (model?.Event == null)
            {
                cityId = string.Empty;
            }
            else
            {
                cityId = model.Event.SameAddressAsOganizer ? model.Event?.Organizer?.Address?.CityId.ToString() ?? model.Event?.Address?.CityId.ToString() : model.Event?.Address?.CityId.ToString();
            }

            ViewBag.Cities    = new SelectList(GetCities(_db), "CityId", "Name", cityId);
            ViewBag.Companies = new SelectList(_db.Companies, "CompanyId", "Name", model?.Event?.OrganizerId);
        }
예제 #7
0
 public ActionResult RemoveContact(CrudEventVm eventContact, int index)
 {
     UrlsContact();
     eventContact.Contacts?.RemoveAt(index);
     return(PartialView("_Contacts", eventContact.Contacts));
 }