public ActionResult Create(Together together)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    together.HostedBy = User.Identity.Name;
                    together.TinyURL  = User.Identity.TinyURL();
                    together.UserName = User.Identity.UserName();

                    Attendee attendee = new Attendee();
                    attendee.AttendeeBy = User.Identity.Name;
                    attendee.UserName   = User.Identity.UserName();
                    attendee.TinyURL    = User.Identity.TinyURL();
                    together.Attendees.Add(attendee);

                    TogetherRepository.Add(together);
                    TogetherRepository.Save();
                    return(RedirectToAction("Details", new { id = together.TogetherID }));
                }
                catch
                {
                    ModelState.AddRuleViolations(together.GetRuleViolations());
                    return(View(new TogetherFormViewModel(together)));
                }
            }
            return(View(new TogetherFormViewModel(together)));
        }
Beispiel #2
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.HostedBy = User.Identity.Name;

                    RSVP rsvp = new RSVP();
                    rsvp.AttendeeName = User.Identity.Name;
                    dinner.RSVPs.Add(rsvp);

                    dinnerRepository.Add(dinner);

                    dinnerRepository.Save();

                    return(RedirectToAction("Details", new { id = dinner.DinnerID }));
                }
                catch
                {
                    ModelState.AddRuleViolations(dinner.GetRuleViolations());
                }
            }

            return(View(new DinnerFormViewModel(dinner)));
        }
Beispiel #3
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            Dinner dinner = dinnerRepository.GetDinner(id);

            if (!dinner.IsHostedBy(User.Identity.Name))
            {
                return(View("InvalidOwner"));
            }
            else
            {
                try
                {
                    UpdateModel(dinner);

                    dinnerRepository.Save();

                    return(RedirectToAction("Details", new { id = dinner.DinnerID }));
                }
                catch
                {
                    ModelState.AddRuleViolations(dinner.GetRuleViolations());

                    return(View(new DinnerFormViewModel(dinner)));
                }
            }
        }
Beispiel #4
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            int count             = 0;
            List <WeightRecord> r = weightRecords.GetWeights(null, id, null, null, "", out count);

            try
            {
                // Retrieve existing weight record

                if (r.Count > 0)
                {
                    // Update weight with form posted values
                    //r[0].Date = Convert.ToDateTime(Request.Form["Date"]);
                    //r[0].Weight = Convert.ToDouble(Request.Form["Weight"]);

                    UpdateModel(r[0]);

                    r[0].Validate();
                    weightRecords.Update(r[0]);
                }
                //// Persist changes back to database
                //// Perform HTTP redirect to details page for the saved Dinner
                return(RedirectToAction("Details", new { id = r[0].WeightRecordID }));
            }
            catch
            {
                ModelState.AddRuleViolations(r[0].GetRuleViolations());
                return(View(r[0]));
            }
        }
        private ActionResult Save(DinnerFormViewModel viewModel)
        {
            Dinner dinner = viewModel.Dinner.ToModel(_dataContext);

            ViewResult viewResult = ModificationNotAuthorized(dinner);

            if (viewResult != null)
            {
                return(viewResult);
            }

            if (ModelState.IsValid && dinner.IsValid)
            {
                _dinnerRepository.Save();

                return(RedirectToAction(ActionNames.Details, new { id = dinner.DinnerID }));
            }
            else
            {
                IEnumerable <RuleViolation> ruleViolations = dinner.GetRuleViolations();
                ModelState.AddRuleViolations(ruleViolations);

                DinnerFormViewModel viewModel2 = CreateFormViewModel(dinner);
                return(View(viewModel2));
            }
        }
Beispiel #6
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            Director director = directorRepo.GetDirector(id);

            try
            {
                UpdateModel(director);
                directorRepo.Save();

                return(RedirectToAction("Index"));
            }
            catch
            {
                ModelState.AddRuleViolations(director.GetRuleViolations());
                return(View(director));
            }
        }
Beispiel #7
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            Genre genre = genreRepo.GetGenre(id);

            try
            {
                UpdateModel(genre);
                genreRepo.Save();

                return(RedirectToAction("Index"));
            }
            catch
            {
                ModelState.AddRuleViolations(genre.GetRuleViolations());
                return(View(genre));
            }
        }
Beispiel #8
0
    public ActionResult Edit(int id, FormCollection formValues)
    {
        Dinner dinner = dinnerRepository.GetDinner(id);

        try {
            UpdateModel(dinner);

            dinnerRepository.Save();

            return(RedirectToAction("Details", new { id = dinner.DinnerID }));
        }
        catch {
            ModelState.AddRuleViolations(dinner.GetRuleViolations());

            return(View(dinner));
        }
    }
Beispiel #9
0
        public ActionResult Edit(string key, FormCollection formValues)
        {
            Blog blog = repo.FindByKey(key);

            try
            {
                UpdateModel(blog);
                repo.Save();

                return(RedirectToAction("Details", new { key = blog.Code }));
            }
            catch
            {
                ModelState.AddRuleViolations(blog.GetRuleViolations());
                return(View());
            }
        }
Beispiel #10
0
 public ActionResult Create(Blog blog)
 {
     if (ModelState.IsValid)
     {
         try
         {
             repo.Create(blog);
             return(RedirectToAction("Details", new { key = blog.Code }));
         }
         catch
         {
             ModelState.AddRuleViolations(blog.GetRuleViolations());
             return(View(blog));
         }
     }
     return(View(blog));
 }
Beispiel #11
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            Movie movie = movieRepo.GetMovie(id);
            MovieFormViewModel viewMovie = new MovieFormViewModel(movie);

            try
            {
                UpdateModel(viewMovie);
                movieRepo.Save();

                return(RedirectToAction("Details", new { id = movie.movie_id }));
            }
            catch
            {
                ModelState.AddRuleViolations(movie.GetRuleViolations());
                return(View(new MovieFormViewModel(movie)));
            }
        }
Beispiel #12
0
    public ActionResult Create(Dinner dinner)
    {
        if (ModelState.IsValid)
        {
            try {
                dinner.HostedBy = "SomeUser";

                dinnerRepository.Add(dinner);
                dinnerRepository.Save();

                return(RedirectToAction("Details", new{ id = dinner.DinnerID }));
            }
            catch {
                ModelState.AddRuleViolations(dinner.GetRuleViolations());
            }
        }

        return(View(dinner));
    }
Beispiel #13
0
        public ActionResult CommentCreate(Comment comment)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    repo.Create(comment);
                    return(RedirectToAction("Details", new { key = comment.Blog.Code }));
                }
                catch
                {
                    ModelState.AddRuleViolations(comment.GetRuleViolations());
                    ViewData["comment"] = comment;
                    return(View("Details", comment.Blog));
                }
            }

            return(View("Details", comment.Blog));
        }
Beispiel #14
0
        public ActionResult Create(Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    ticketRepository.Add(ticket);
                    ticketRepository.Save();

                    return(RedirectToAction("Details", new { id = ticket.ticket_id }));
                }
                catch
                {
                    ModelState.AddRuleViolations(ticket.GetRuleViolations());
                    ControllerHelpers.CreateDropDownListViewBag(this);
                }
            }
            ControllerHelpers.CreateDropDownListViewBag(this);
            return(View(ticket));
        }
Beispiel #15
0
        public ActionResult Create(WeightRecord r2)
        {
            WeightRecord r = new WeightRecord();

            try
            {
                r.UserName = User.Identity.Name;

                UpdateModel(r);

                int newId = weightRecords.Add(r);

                return(RedirectToAction("Details", new { id = newId }));
            }
            catch
            {
                ModelState.AddRuleViolations(r.GetRuleViolations());
                return(View(r));
            }
        }
Beispiel #16
0
        public ActionResult Create(Genre genre)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    UpdateModel(genre);

                    genreRepo.Add(genre);
                    genreRepo.Save();

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    ModelState.AddRuleViolations(genre.GetRuleViolations());
                }
            }

            return(View(genre));
        }
Beispiel #17
0
        public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    UpdateModel(movie);
                    movieRepo.Add(movie);

                    movieRepo.Save();

                    return(RedirectToAction("Details", new { id = movie.movie_id }));
                }
                catch
                {
                    ModelState.AddRuleViolations(movie.GetRuleViolations());
                }
            }

            return(View(new MovieFormViewModel(movie)));
        }
Beispiel #18
0
        public ActionResult CreateModal(Director director)
        {
            //Request.IsAjaxRequest() &&
            if (ModelState.IsValid)
            {
                try
                {
                    UpdateModel(director);

                    directorRepo.Add(director);
                    directorRepo.Save();
                }
                catch
                {
                    ModelState.AddRuleViolations(director.GetRuleViolations());
                    return(View(director));
                }
            }

            return(JavaScript("newDirectorComplete('" + director.director_id.ToString() + "', '" + director.FullName + "');"));
        }
Beispiel #19
0
        public ActionResult Create(Director director)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    UpdateModel(director);

                    directorRepo.Add(director);
                    directorRepo.Save();

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    ModelState.AddRuleViolations(director.GetRuleViolations());
                }
            }

            return(View(director));
        }
        public ActionResult Edit(int id, FormCollection formValues)
        {
            // Retrieve existing dinner
            Dinner dinner = dinnerRepository.GetDinner(id);

            try
            {
                UpdateModel(dinner);

                // Persist changes back to db
                dinnerRepository.Save();

                // Perform HTTP redirect to details page for the saved Dinner
                return(RedirectToAction("Details", new { id = dinner.DinnerID }));
            }

            catch
            {
                ModelState.AddRuleViolations(dinner.GetRuleValidations());
                return(View(dinner));
            }
        }
        public ActionResult Edit(int id, FormCollection collection)
        {
            ConnectionModel connection = null;

            try
            {
                connection = this._connectionRepository.GetConnection(id);
                if (connection == null)
                {
                    return(View("NotFound", "The specified connection was not found"));
                }

                this.UpdateModel(connection);
                connection.ConnectionParameters.Clear();
                connection.ConnectionParameters.AddRange(ConnectionParameterModel.FromFormCollection(collection));

                if (connection.IsValid)
                {
                    IEnumerable <RuleViolation> ruleViolations = null;
                    if (!this._connectionRepository.IsValid(connection, out ruleViolations))
                    {
                        ModelState.AddRuleViolations(ruleViolations);
                        return(View(connection));
                    }
                    this._connectionRepository.Save();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddRuleViolations(connection.GetRuleViolations());
                    return(View(connection));
                }
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Details(Post post)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    post.PostDate = DateTime.Now;
                    post.PostBy   = User.Identity.Name;
                    post.UserName = User.Identity.UserName();
                    post.TinyURL  = User.Identity.TinyURL();

                    TogetherRepository.AddPost(post);
                    TogetherRepository.Save();
                    return(RedirectToAction("Details", new { id = post.TogetherID }));
                }
                catch
                {
                    ModelState.AddRuleViolations(post.GetRuleViolations());
                }
            }
            ViewData["PostForm"] = post;
            return(View(post.Together));
        }
        public ActionResult Edit(int id, FormCollection formValues)
        {
            Together together = TogetherRepository.GetTogether(id);

            if (!together.IsHostedBy(User.Identity.Name))
            {
                return(View("InvalidOwner"));
            }

            try
            {
                UpdateModel(together);

                TogetherRepository.Save();

                return(RedirectToAction("Details", new { id = together.TogetherID }));
            }
            catch
            {
                ModelState.AddRuleViolations(together.GetRuleViolations());
                return(View(new TogetherFormViewModel(together)));
            }
        }
Beispiel #24
0
        public ActionResult Create(Party party)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    party.HostedBy = User.Identity.Name;
                    Reservation res = new Reservation();
                    res.Attender = User.Identity.Name;
                    party.Reservations.Add(res);


                    partyRepository.Add(party);
                    partyRepository.Save();
                    return(RedirectToAction("Details", new { id = party.PartyID }));
                }
                catch
                {
                    ModelState.AddRuleViolations(party.GetRuleViolations());
                }
            }
            return(View(party));
        }
Beispiel #25
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            Party party = partyRepository.GetParty(id);

            if (!party.IsHostedBy(User.Identity.Name))
            {
                return(View("Invalid"));
            }

            try
            {
                UpdateModel(party);
                partyRepository.Save();
                return(RedirectToAction("Details", new { id = party.PartyID }));
            }
            catch
            {
                ModelState.AddRuleViolations(party.GetRuleViolations());


                return(View(party));
            }
        }
Beispiel #26
0
        public ActionResult Edit(int id, FormCollection formValues)
        {
            // Get current ticket
            Ticket ticket = ticketRepository.GetTicket(id);

            try
            {
                // Update ticket with posted data
                UpdateModel(ticket);

                ticketRepository.Save();

                //Return to details page of the saved ticket
                return(RedirectToAction("Details", new { id = ticket.ticket_id }));
            }
            catch
            {
                ModelState.AddRuleViolations(ticket.GetRuleViolations());

                ControllerHelpers.CreateDropDownListViewBag(this);

                return(View(ticket));
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            ConnectionModel connection = null;

            try
            {
                connection = new ConnectionModel();
                this.UpdateModel(connection);
                connection.ConnectionParameters.Clear();
                connection.ConnectionParameters.AddRange(ConnectionParameterModel.FromFormCollection(collection));

                if (connection.IsValid)
                {
                    IEnumerable <RuleViolation> ruleViolations = null;
                    if (!this._connectionRepository.IsValid(connection, out ruleViolations))
                    {
                        ModelState.AddRuleViolations(ruleViolations);
                        return(View(connection));
                    }

                    this._connectionRepository.AddConnection(connection);
                    this._connectionRepository.Save();
                }
                else
                {
                    ModelState.AddRuleViolations(connection.GetRuleViolations());
                    return(View(connection));
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }