public async Task <IActionResult> Add(CategoryViewModel viewModel)
        {
            if (viewModel == null)
            {
                ModelState.AddModelError(string.Empty, "View model is null");
            }

            if (ModelState.IsValid)
            {
                ProcessResult <bool> categoryUniqueResult = await CategoryViewModelIsValid(viewModel);

                ModelState.AddProcessResultErrors(categoryUniqueResult);
            }

            if (ModelState.IsValid)
            {
                CategoryViewModelMapper mapper          = new CategoryViewModelMapper();
                PhotoCategory           repositoryModel = mapper.BuildRepositoryModel(viewModel, null);
                ProcessResult <bool>    saveResult      = _db.SaveAdditions(repositoryModel);
                ModelState.AddProcessResultErrors(saveResult);
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                CategoryViewModelMapper mapper = new CategoryViewModelMapper();
                viewModel = mapper.BuildViewModelDropdownCriteria(viewModel);
                return(View(viewModel));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> MyProfile(UserViewModel viewModel)
        {
            if (viewModel != null)
            {
                viewModel.UserName = User.Identity.Name;
            }
            else
            {
                ModelState.AddModelError(string.Empty, "View model is empty");
            }

            if (ModelState.IsValid)
            {
                ProcessResult <bool> uniqueUserResult = await UserIdentityDetailsAreUniqueAsync(viewModel, User.Identity.Name);

                ModelState.AddProcessResultErrors(uniqueUserResult);
            }

            if (ModelState.IsValid)
            {
                ProcessResult <bool> result = await SaveUserViewModel(viewModel, FormMode.Edit);

                ModelState.AddProcessResultErrors(result);
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Category"));
            }
            else
            {
                return(View(viewModel));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete(string id)
        {
            ProcessResult <UserViewModel> viewModelProcess = await GetUserViewModel(id);

            ModelState.AddProcessResultErrors(viewModelProcess);
            return(View(viewModelProcess.Result));
        }
Esempio n. 4
0
        public async Task <IActionResult> MyProfile()
        {
            string userName = User.Identity.Name;
            ProcessResult <UserViewModel> viewModelProcess = await GetUserViewModel(userName);

            ModelState.AddProcessResultErrors(viewModelProcess);
            return(View(viewModelProcess.Result));
        }
        public async Task <IActionResult> Edit(int id)
        {
            ProcessResult <PhotoCategory> categoryProcessResult = await GetPhotoCategory(id);

            ModelState.AddProcessResultErrors(categoryProcessResult);
            CategoryViewModelMapper mapper    = new CategoryViewModelMapper();
            CategoryViewModel       viewModel = mapper.BuildViewModel(categoryProcessResult.Result);

            return(View(viewModel));
        }
        public async Task <IActionResult> Delete(DeleteCategoryViewModel viewModel)
        {
            ProcessResult <PhotoCategory> categoryProcessResult = await GetPhotoCategory(viewModel.CategoryId);

            ModelState.AddProcessResultErrors(categoryProcessResult);
            if (ModelState.IsValid)
            {
                ProcessResult <bool> saveResult = _db.SaveRemoves(categoryProcessResult.Result);
                ModelState.AddProcessResultErrors(saveResult);
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(viewModel));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Add(UserViewModel viewModel)
        {
            if (viewModel == null)
            {
                ModelState.AddModelError(string.Empty, "View model is empty");
            }

            if (ModelState.IsValid)
            {
                ProcessResult <bool> uniqueUserResult = await UserIdentityDetailsAreUniqueAsync(viewModel);

                ModelState.AddProcessResultErrors(uniqueUserResult);

                if (string.IsNullOrEmpty(viewModel.Password))
                {
                    ModelState.AddModelError("Password", "A password must be entered");
                }
                if (string.IsNullOrEmpty(viewModel.ConfirmPassword))
                {
                    ModelState.AddModelError("ConfirmPassword", "A password must be entered");
                }
            }

            if (ModelState.IsValid)
            {
                ProcessResult <bool> result = await SaveUserViewModel(viewModel, FormMode.Add);

                ModelState.AddProcessResultErrors(result);
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(viewModel));
            }
        }
        public async Task <ActionResult> Edit(CategoryViewModel viewModel)
        {
            if (viewModel == null)
            {
                ModelState.AddModelError(string.Empty, "View model is null");
            }

            if (ModelState.IsValid)
            {
                ProcessResult <bool> categoryUniqueResult = await CategoryViewModelIsValid(viewModel, viewModel.CategoryId);

                ModelState.AddProcessResultErrors(categoryUniqueResult);
            }

            if (ModelState.IsValid)
            {
                ProcessResult <PhotoCategory> categoryProcessResult = await GetPhotoCategory(viewModel.CategoryId);

                ModelState.AddProcessResultErrors(categoryProcessResult);

                if (categoryProcessResult.Success)
                {
                    CategoryViewModelMapper mapper = new CategoryViewModelMapper();

                    ProcessResult <List <Photograph> > photosToUpdateResult = new ProcessResult <List <Photograph> >();
                    if ((viewModel.StatusCode == CategoryStatusCodes.Judging || viewModel.StatusCode == CategoryStatusCodes.Completed) &&
                        categoryProcessResult.Result.StatusCode != viewModel.StatusCode)
                    {
                        photosToUpdateResult = await GetPhotoNameUpdatesAsync(viewModel.CategoryId, viewModel.PhotoNamingThemeCode);
                    }

                    // Save photo naming changes
                    ProcessResult <bool> saveResult = new ProcessResult <bool>();
                    if (photosToUpdateResult.Success && (photosToUpdateResult.Result?.Count ?? 0) > 0)
                    {
                        saveResult = _db.SaveUpdates(photosToUpdateResult.Result.ToArray());
                    }

                    // Save category changes
                    if (photosToUpdateResult.Success && saveResult.Success)
                    {
                        PhotoCategory repositoryModel = mapper.BuildRepositoryModel(viewModel, categoryProcessResult.Result);
                        saveResult = _db.SaveUpdates(repositoryModel);
                    }

                    ModelState.AddProcessResultErrors(photosToUpdateResult);
                    ModelState.AddProcessResultErrors(saveResult);
                }
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                CategoryViewModelMapper mapper = new CategoryViewModelMapper();
                viewModel = mapper.BuildViewModelDropdownCriteria(viewModel);
                return(View(viewModel));
            }
        }