public ActionResult Edit(EventViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var database = new EventSpotDbContext())
                {
                    //Get article from database
                    var events = database.Events
                                 .FirstOrDefault(a => a.Id == model.Id);

                    events.EventName        = model.EventName;
                    events.EventDate        = model.EventDate;
                    events.StartTime        = model.StartTime;
                    events.EventDescription = model.EventDescription;
                    events.CategoryId       = model.CategoryId;
                    events.CityId           = model.CityId;
                    this.SetEventTags(events, model, database);
                    database.Entry(events).State = EntityState.Modified;
                    database.SaveChanges();

                    return(RedirectToAction("Main"));
                }
            }
            return(View(model));
        }
        public ActionResult Edit(City city)
        {
            if (ModelState.IsValid)
            {
                using (var database = new EventSpotDbContext())
                {
                    database.Entry(city).State = EntityState.Modified;
                    database.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(city));
        }
示例#3
0
        public ActionResult Edit(string id, EditUserViewModel viewModel)
        {
            //Check if model is valid
            if (ModelState.IsValid)
            {
                using (var database = new EventSpotDbContext())
                {
                    //Get user from databese
                    var user = database.Users.FirstOrDefault(u => u.Id == id);

                    //Check if user exists
                    if (user == null)
                    {
                        return(HttpNotFound());
                    }

                    //If password field is not empty, change password
                    if (!string.IsNullOrEmpty(viewModel.Password))
                    {
                        var hasher       = new PasswordHasher();
                        var passwordHash = hasher.HashPassword(viewModel.Password);
                        user.PasswordHash = passwordHash;
                    }

                    //Set user properties
                    user.Email    = viewModel.User.Email;
                    user.FullName = viewModel.User.FullName;
                    user.UserName = viewModel.User.Email;
                    this.SetUserRoles(user, database, viewModel);

                    //Save changes
                    database.Entry(user).State = EntityState.Modified;
                    database.SaveChanges();

                    return(RedirectToAction("List"));
                }
            }
            return(View(viewModel));
        }