public bool CreateEvent(EventModel model)
        {
            using (var ctx = new EventContext())
            {
                model.Publisher = (from c in ctx.Customers
                                   where c.Login == model.Publisher.Login
                                   select c).FirstOrDefault();

                if (!model.Publisher.IsBan && !model.Publisher.IsDeleted)
                {
                    model.Type = (from t in ctx.EventTypes
                                  where t.Id == model.Type.Id
                                  select t).FirstOrDefault();

                    model.PersonsCategory = (from c in ctx.PersonCategories
                                             where c.Id == model.PersonsCategory.Id
                                             select c).FirstOrDefault();

                    model.City = (from c in ctx.Cities
                                  where c.Id == model.City.Id
                                  select c).FirstOrDefault();

                    if (model.City != default(EventCity))
                    {
                        model.IsPublished = true;

                        ctx.Events.Add(model);
                        ctx.SaveChanges();
                        return true;
                    }
                }
            }
            return false;
        }
        public ActionResult SaveEvent()
        {
            string userName = HttpContext.User.Identity.Name;
            var model = new EventModel
            {
                Title = currentEvent.Title,
                StartTime = currentEvent.StartTime,
                EndTime = currentEvent.EndTime,
                Type = new EventType { Id = currentEvent.SelectedTypeId },
                PersonsCategory = new EventPersonCategory { Id = currentEvent.SelectedPersonsCategoryId },
                Place = currentEvent.Place,
                MainPhoto = TempEventPhoto,
                Organizers = currentEvent.Organizers,
                Description = currentEvent.Description,
                ShortDescription = currentEvent.ShortDescription,
                Sponsors = currentEvent.Sponsors,
                IsCharitable = currentEvent.IsCharitable,
                isFreeEntrance = currentEvent.IsFreeEntrance,
                Enter = currentEvent.Enter,
                Publisher = new EventCustomer { Login = userName },
                City = new EventCity { Id = currentEvent.CityId}
            };

            if (manager.CreateEvent(model))
            {
                return RedirectToAction("Events", "Profile");
            }
            return View("Index", currentEvent);
        }
 private bool AddNewLike(bool likes, EventContext ctx, EventModel curEvent, EventCustomer customer)
 {
     var likeType = likes ? ctx.LikeCommentTypes.FirstOrDefault(l => l.Type == "positive")
                                  : ctx.LikeCommentTypes.FirstOrDefault(l => l.Type == "negative");
     if (likeType != default(LikeCommentType))
     {
         var like = new EventLike { Type = likeType, Event = curEvent, Customer = customer };
         ctx.Likes.Add(like);
         if (likes)
         {
             curEvent.Likes.Add(like);
         }
         else
         {
             curEvent.Dislikes.Add(like);
         }
         return true;
     }
     return false;
 }
 public void CreateModel(IModel model, EventModel current)
 {
     model.Id = current.Id;
     model.Description = current.Description;
     model.EndTime = current.EndTime;
     model.Enter = current.Enter;
     model.IsCharitable = current.IsCharitable;
     model.IsFreeEntrance = current.isFreeEntrance;
     model.MainPhoto = new PhotoManager().GetImage(current.MainPhoto, Server.MapPath("~"), true);
     //model.Photos = current.Photos;
     model.Organizers = current.Organizers;
     model.Place = current.Place;
     model.ShortDescription = current.ShortDescription;
     model.Sponsors = current.Sponsors;
     model.StartTime = current.StartTime;
     model.Title = current.Title;
 }