예제 #1
0
        public ActionResult Edit(MultimediaTypeViewMode viewModel)
        {
            // Sprawdź status modelu
            if (ModelState.IsValid)
            {
                try
                {
                    // Zapisz obiekt do repozytorium
                    var response = _repository.Save(viewModel.MultimediaType);
                    if (response != null && !response.Accepted)
                    {
                        foreach (var r in response.Errors)
                        {
                            var key = string.IsNullOrEmpty(r.Property) ? "" : ("MultimediaType." + r.Property);
                            ModelState.AddModelError(key, r.Message);
                        }
                        return(View(viewModel));
                    }
                }
                catch (Exception ex)
                {
                    // Obsłuż błędy
                    DbValidationErrorHandler.ModelHandleException(ex, ModelState, "MultimediaType");
                    return(View(viewModel));
                }

                return(RedirectToAction("Index", "Default", new { ctr = "MultimediaTypes" }));
            }
            else
            {
                return(View(viewModel));
            }
        }
예제 #2
0
        public ActionResult Edit(int?id)
        {
            var ids = User.GetUserIDInt();
            var u   = _usersRepository.Users.Single(it => it.Id == ids);

            ViewBag.AdPoints = u.AdPoints;

            // Pobierz typ z repozytorium
            var type = _repository.GetById(id ?? 0);

            // Zbuduj i zwróć model
            var viewModel = new MultimediaTypeViewMode
            {
                MultimediaType = type ?? new ADServerDAL.Models.Type()
            };

            return(View(viewModel));
        }