示例#1
0
        public bool ChangeEvent(ChangeModel changedModel)
        {
            using (var ctx = new EventContext())
            {
               var changeEvent =  ctx.Events.Include("City").Include("Publisher").FirstOrDefault(e => e.Id == changedModel.Id);
               if (changeEvent != default(EventModel))
               {
                   changeEvent.Description = changedModel.Description;
                   changeEvent.EndTime = changedModel.EndTime;
                   changeEvent.Enter = changedModel.Enter;
                   changeEvent.IsCharitable = changedModel.IsCharitable;
                   changeEvent.isFreeEntrance = changedModel.IsFreeEntrance;
                   changeEvent.Organizers = changedModel.Organizers;
                   changeEvent.PersonsCategory = ctx.PersonCategories.FirstOrDefault(p=>p.Id == changedModel.SelectedPersonsCategoryId);
                   //changeEvent.Photos = changedModel.Photos;
                   changeEvent.Place = changedModel.Place;
                   changeEvent.ShortDescription = changedModel.ShortDescription;
                   changeEvent.Sponsors = changedModel.Sponsors;
                   changeEvent.StartTime = changedModel.StartTime;
                   changeEvent.Title = changedModel.Title;
                   changeEvent.Type = ctx.EventTypes.FirstOrDefault(t=>t.Id == changedModel.SelectedTypeId);

                   ctx.SaveChanges();
               }
            }
            return true;
        }
        public ActionResult ChangeEvent()
        {
            string userName = HttpContext.User.Identity.Name;

            ChangeModel model = new ChangeModel();
            model.Title = currentEvent.Title;
            model.StartTime = currentEvent.StartTime;
            model.Sponsors = currentEvent.Sponsors;
            model.ShortDescription = currentEvent.ShortDescription;
            model.SelectedTypeId = currentEvent.SelectedTypeId;
            model.SelectedPersonsCategoryId = currentEvent.SelectedPersonsCategoryId;
            model.Place = currentEvent.Place;
            model.Photos = currentEvent.Photos;
            model.Organizers = currentEvent.Organizers;
            model.IsFreeEntrance = currentEvent.IsFreeEntrance;
            model.IsCharitable = currentEvent.IsCharitable;
            model.Id = currentEvent.Id;
            model.Enter = currentEvent.Enter;
            model.EndTime = currentEvent.EndTime;
            model.Description = currentEvent.Description;

            //дописати додавання інших фото
            if (manager.ChangeEvent(model))
            {
                return RedirectToAction("EventDetails", "Event", new {id = model.Id});
            }
            return View("Edit", currentEvent);
        }