Exemplo n.º 1
0
        public ActionResult Edit(CampaignPriorityViewModel viewModel)
        {
            // Sprawdzenie stanu modelu
            if (ModelState.IsValid)
            {
                try
                {
                    // Zapis obiektu do repozytorium
                    var response = _repository.Save(viewModel.Priority);
                    if (response != null && !response.Accepted)
                    {
                        foreach (var r in response.Errors)
                        {
                            var key = string.IsNullOrEmpty(r.Property) ? "" : ("Priority." + r.Property);
                            ModelState.AddModelError(key, r.Message);
                        }
                        return(View(viewModel));
                    }
                }
                catch (Exception ex)
                {
                    // Obsługa błędów
                    DbValidationErrorHandler.ModelHandleException(ex, ModelState, "Priority");
                    return(View(viewModel));
                }

                return(RedirectToAction("Index", "Default", new { ctr = "CampaignPriorities" }));
            }
            // Niepoprawne dane - zwróc formularz użytkownikowi
            Error("Niepoprawne dane");
            return(View(viewModel));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int?id)
        {
            var ids = User.GetUserIDInt();
            var u   = _usersRepository.Users.Single(it => it.Id == ids);

            ViewBag.AdPoints = u.AdPoints;
            //Zbudowanie i zwrócenie modelu
            var viewModel = new CampaignPriorityViewModel
            {
                Priority = _repository.GetById(id ?? 0) ?? new Priority()
            };

            return(View(viewModel));
        }