Beispiel #1
0
        public async Task <IActionResult> Delete(DeleteViewModel model)
        {
            try
            {
                var findItem = await _shopRepository.GetSingleAsync(model.Id, x => x.Wells);

                if (findItem == null)
                {
                    return(NotFound());
                }
                ///Каскадно удаляем сначала все скважины в цехе, т.к. EF настроен как OnDelete(DeleteBehavior.Restrict)
                if (findItem.Wells.Any())
                {
                    _wellRepository.DeleteRange(findItem.Wells);
                }
                ///Затем удаляем сам цех
                _shopRepository.Delete(findItem);
                return(Ok());
            }
            catch (Exception e)
            {
                Log.Error(e, "ShopController.Delete");
                return(BadRequest(_messageModelBuilder.CreateModel("500", e.Message)));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Delete(
            [FromRoute] string appId,
            [FromRoute] string recordName)
        {
            var user = await GetCurrentUserAsync();

            var app = await _dbContext.Apps.FindAsync(appId);

            if (app == null)
            {
                return(NotFound());
            }
            if (app.CreatorId != user.Id)
            {
                return(Unauthorized());
            }
            var model = new DeleteViewModel(user)
            {
                AppId      = appId,
                RecordName = recordName,
                AppName    = app.AppName
            };

            return(View(model));
        }
        public async Task <IActionResult> Delete(DeleteViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                model.Recover(user);
                return(View(model));
            }
            try
            {
                await _sitesService.DeleteSiteAsync(await accesstoken, user.SiteName);

                user.SiteName = string.Empty;
                await _dbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(CreateSite)));
            }
            catch (AiurUnexceptedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.ModelStateValid = false;
                model.Recover(user);
                return(View(model));
            }
        }
        public async Task <IActionResult> DeletePersonalData(DeleteViewModel model)
        {
            ViewBag.ActiveTab = 3;
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!await _userManager.CheckPasswordAsync(user, model.Password))
            {
                ModelState.AddModelError(string.Empty, "Password not correct.");
                return(View("MyAccount", new AccountViewModel()));
            }

            var result = await _userManager.DeleteAsync(user);

            var userId = await _userManager.GetUserIdAsync(user);

            if (!result.Succeeded)
            {
                throw new InvalidOperationException($"Unexpected error occurred deleteing user with ID '{userId}'.");
            }

            await _signInManager.SignOutAsync();

            _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);

            return(Redirect("~/"));
        }
        public async Task <ActionResult> Index(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Guid?notificationId;

            if (model.IsExportNotification.GetValueOrDefault())
            {
                notificationId = await mediator.SendAsync(new GetNotificationIdByNumber(model.NotificationNumber));
            }
            else
            {
                notificationId = await mediator.SendAsync(new GetImportNotificationIdByNumber(model.NotificationNumber));
            }

            if (notificationId == null)
            {
                ModelState.AddModelError("NotificationNumber", DeleteNotificationControllerResources.NumberNotExist);

                return(View(model));
            }

            var deleteModel = new DeleteViewModel(model, notificationId.GetValueOrDefault());

            return(RedirectToAction("Check", deleteModel));
        }
        public async Task <IActionResult> Delete([FromRoute] ulong server, [FromRoute] uint quote)
        {
            var authEntry = HttpContext.GetAuthEntry();

            if (authEntry is null)
            {
                return(Redirect("/login"));
            }

            var userGuilds = await userService.GetAllowedUserGuilds(authEntry);

            if (!userGuilds.Any(x => x.Id == server))
            {
                return(Unauthorized());
            }

            var named_audio = await quoteBotRepo.GetNamedAudioByAudioOwnerId(quote);

            if (named_audio.AudioOwner.OwnerId != server)
            {
                return(BadRequest());
            }
            var viewModel = new DeleteViewModel(named_audio, server);

            return(View(viewModel));
        }
Beispiel #7
0
        public DeleteView(ClassEx selectedClassEx = null, TeacherEx selectedTeacher = null) // tjek om det er teacherex eller class
        {
            InitializeComponent();

            if (viewModel == null)
            {
                viewModel = new DeleteViewModel();
            }

            if (selectedClassEx != null) // er det teacher eller class der ønskes slettet?
            {
                viewModel.ViewstateObject    = Enums.ViewstateObject.Class;
                viewModel.CurrentClass       = selectedClassEx;
                datagridClassesEx.Visibility = Visibility.Hidden;
                cbListofTeachers.Visibility  = Visibility.Hidden;
                butAssociate.Visibility      = Visibility.Hidden;
            }
            else if (selectedTeacher != null)
            {
                viewModel.ViewstateObject  = Enums.ViewstateObject.Teacher;
                viewModel.CurrentTeacherEx = selectedTeacher;
                listboxStudents.Visibility = Visibility.Hidden;
                cbListofClasses.Visibility = Visibility.Hidden;
            }

            DataContext = viewModel;
            InitializeEvents();
        }
Beispiel #8
0
        public ActionResult Delete(string username) // máme username poslané pomocí GET
        {
            if (username == null)                   // neplatné username!
            {
                TempData.Add("error", "Před smazáním musíte vybrat existujícího uživatele.");
                return(RedirectToAction("Users", "Account"));
            }

            DeleteViewModel DVM = new DeleteViewModel();

            try
            {
                ApplicationUser user = UserManager.FindByName(username);
                if (user.UserName == User.Identity.Name) // jedná se o právě přihlášeného uživatele (admina)
                {
                    TempData.Add("error", "Nemůžete smazat svůj uživatelský účet.");
                    return(RedirectToAction("Users", "Account")); // sám sebe nesmí mazat
                }
                else if (!UserManager.IsInRole(user.Id, "user"))  // nejedná se o uživatele v roli "user"!
                {
                    TempData.Add("error", "Lze mazat pouze uživateli v roli 'user', nikoli jiné administrátory.");
                    return(RedirectToAction("Users", "Account"));
                }

                //   DVM.UserId = user.Id;
                DVM.UserName = username;
                return(View(DVM)); // formulář pro potvrzení smazání uživatele
            }
            catch                  // asi bylo neplatné username!
            {
                TempData.Add("error", "Uživatele '" + username + "' nelze smazat (uživatel neexistuje).");
                return(RedirectToAction("Users", "Account"));
            }
        }
        public async Task <IActionResult> Delete([FromBody] DeleteViewModel model)
        {
            _context.Clients.Remove(await _context.Clients.SingleOrDefaultAsync(c => c.Id == model.Id));
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public IActionResult Index(DeleteViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_redisRepository.Exists(viewModel.KeyToDelete))
                    {
                        _redisRepository.Delete(viewModel.KeyToDelete);

                        new SetTempDataMessage()
                        .Display(TempData, "OK", $"The key {viewModel.KeyToDelete} has been removed.");
                    }
                    else
                    {
                        new SetTempDataMessage()
                        .Display(TempData, "Warning", $"Key {viewModel.KeyToDelete} was not found.", SetTempDataMessage.CssClassNameEnum.alert_warning);
                    }
                }
            }
            catch (Exception ex)
            {
                new SetTempDataMessage()
                .Display(TempData, "Error", ex.Message, SetTempDataMessage.CssClassNameEnum.alert_danger);
            }

            return(View(viewModel));
        }
Beispiel #11
0
        public ActionResult Delete(DeleteViewModel vmDelete)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    TempData["ErrorMessage"] = "Problem deleting record. Try again.";
                    return(RedirectToAction("Index", "AccountTransaction"));
                }

                // update db
                if (!_businessService.AccountTransactionService.DeleteTransaction(vmDelete.Id))
                {
                    ViewData["ErrorMessage"] = "Problem deleting record";
                    return(View("Delete", vmDelete));
                }

                TempData["SuccessMessage"] = "Record deleted";
                return(RedirectToAction("Index", "AccountTransaction"));
            }
            catch (Exception)
            {
                TempData["ErrorMessage"] = "Encountered Problem";
                return(RedirectToAction("Index", "AccountTransaction"));
            }
        }
Beispiel #12
0
        // GET: AccountabilityTypes/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var accountabilityType = await _context.AccountabilityTypes
                                     .SingleOrDefaultAsync(m => m.AccountabilityTypeId == id);

            if (accountabilityType == null)
            {
                return(NotFound());
            }

            DeleteViewModel vm = new DeleteViewModel()
            {
                AccountabilityType = accountabilityType
            };

            vm.AffectedAccountabilities = await _context.Accountabilities.Where(x =>
                                                                                x.AccountabilityTypeId == accountabilityType.AccountabilityTypeId)
                                          .Include(x => x.Accountable)
                                          .Include(x => x.Commissioner)
                                          .ToListAsync();

            vm.CanDelete = vm.AffectedAccountabilities.Count < 1;

            return(View(vm));
        }
Beispiel #13
0
        public ActionResult DeleteConfirmed(DeleteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                ApplicationUser user = UserManager.FindByName(model.UserName);
                UserManager.Delete(user); // odstranění uživatele
                TempData.Add("Message", "Uživatel '" + model.UserName + "' byl smazán.");
                return(RedirectToAction("Users", "Account"));
            }
            catch
            {
                TempData.Add("error", "Uživatele '" + model.UserName + "' se nepodařilo smazat.");
                return(RedirectToAction("Users", "Account"));
            }

            /*
             * WebSenateModels webSenateModels = db.WebSenateModels.Find(id);
             * db.WebSenateModels.Remove(webSenateModels);
             * db.SaveChanges();
             * return RedirectToAction("Index");
             */
        }
Beispiel #14
0
        public async Task <IActionResult> Delete(DeleteViewModel model)
        {
            var user = await GetCurrentUserAsync();

            var app = await _dbContext.Apps.FindAsync(model.AppId);

            if (app == null)
            {
                return(NotFound());
            }
            if (app.CreatorId != user.Id)
            {
                return(Unauthorized());
            }
            if (!ModelState.IsValid)
            {
                model.Recover(user, app.AppName);
                return(View(model));
            }
            try
            {
                var token = await _appsContainer.AccessToken(app.AppId, app.AppSecret);

                await _recordsService.DeleteRecordAsync(token, model.RecordName);

                return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = app.AppId, JustHaveUpdated = true }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.Recover(user, app.AppName);
                return(View(model));
            }
        }
        public async Task <ActionResult> Delete(DeleteViewModel user)
        {
            if (ModelState.IsValid)
            {
                var userFound = await UserManager.FindByIdAsync(user.UserId);

                if (userFound == null)
                {
                    ModelState.AddModelError("", "Usuário não encontrado.");
                }
                else
                {
                    var result = await UserManager.DeleteAsync(userFound);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index"));
                    }

                    AddErrors(result);
                }
            }

            return(View(user));
        }
Beispiel #16
0
        public async Task <IActionResult> Delete(int userId)
        {
            var user = await Authorize();

            if (user == null)
            {
                return(RedirectToAction("Login", "Auth", new { fallbackUrl = HttpContext.Request.Path }));
            }

            if (!user.Roles.Any(r => r.Name == "Администратор"))
            {
                return(Unauthorized());
            }

            if (UserRepository.Get(userId) != null)
            {
                var deleteVM = new DeleteViewModel
                {
                    ConfirmUrl  = Url.Action(nameof(DeleteConfirm), new { userId }),
                    FallbackUrl = Url.Action(nameof(AdminPanel))
                };

                return(View("_ConfirmDelete", deleteVM)); //Страница подтверждения удаления
            }
            else
            {
                return(NotFound());
            }
        }
Beispiel #17
0
        public void Then_Sets_ReservationId(
            GetReservationResult getReservationResult)
        {
            var viewModel = new DeleteViewModel(getReservationResult);

            viewModel.Id.Should().Be(getReservationResult.ReservationId);
        }
        public async Task <IActionResult> Delete(DeleteViewModel viewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("Index", "Home"));
            }

            var product = await this._dbContext
                          .Products
                          .FirstOrDefaultAsync(x => x.Id == viewModel.Id);

            if (product == null)
            {
                return(this.RedirectToAction("Index", "Home"));
            }

            this._dbContext
            .Products
            .Remove(product);

            await this._dbContext
            .SaveChangesAsync();

            return(this.RedirectToAction("Index", "Home"));
        }
Beispiel #19
0
        public void Then_Sets_AccountLegalEntityName(
            GetReservationResult getReservationResult)
        {
            var viewModel = new DeleteViewModel(getReservationResult);

            viewModel.AccountLegalEntityName.Should().Be(getReservationResult.AccountLegalEntityName);
        }
Beispiel #20
0
        public async Task <IActionResult> DeleteAsync(DeleteViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewData["ErrorMessage"] = "Invalid form submission.";
                return(PartialView("_DeleteStock", viewModel));
            }

            BaseResponse _Response     = new BaseResponse();
            string       _UserIDString = __UserManager.GetUserId(User);

            if (Guid.TryParse(_UserIDString, out Guid userUID))
            {
                _Response = await __StockManager.DeleteAsync(new UserUIDAndUIDRequest { UID = viewModel.UID, UserUID = userUID });
            }
            else
            {
                _Response.Success      = false;
                _Response.ErrorMessage = $"You do not have permission to delete the {ENTITY_NAME}";
            }

            if (!_Response.Success)
            {
                return(RedirectToAction("Index", "Stock", new { Area = "Stock", errorMessage = _Response.ErrorMessage }));
            }

            return(RedirectToAction("Index", "Stock", new { Area = "Stock", successMessage = $"{GlobalConstants.SUCCESS_ACTION_PREFIX} deleted {ENTITY_NAME}" }));
        }
Beispiel #21
0
        public void Then_Sets_CourseDescription(
            GetReservationResult getReservationResult)
        {
            var viewModel = new DeleteViewModel(getReservationResult);

            viewModel.CourseDescription.Should().Be(getReservationResult.Course.CourseDescription);
        }
Beispiel #22
0
        public DeleteDialog(string text)
        {
            InitializeComponent();
            var vm = new DeleteViewModel(text);

            DataContext = vm;
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var product = await this._dbContext
                          .Products
                          .FirstOrDefaultAsync(x => x.Id == id);

            if (product == null)
            {
                return(this.RedirectToAction("Index", "Home"));
            }

            var viewModel = new DeleteViewModel()
            {
                Id          = product.Id,
                Name        = product.Name,
                Description = product.Description,
                Price       = product.Price,
                Type        = product.Type
            };

            return(this.View(viewModel));
        }
Beispiel #24
0
        public async Task <IActionResult> Delete(DeleteViewModel model)
        {
            int?sUKPRN = Session.GetInt32("UKPRN");
            int UKPRN;

            if (!sUKPRN.HasValue)
            {
                return(RedirectToAction("Index", "Home", new { errmsg = "Please select a Provider." }));
            }
            else
            {
                UKPRN = sUKPRN ?? 0;
            }

            switch (model.MigrationDeleteOptions)
            {
            case MigrationDeleteOptions.DeleteMigrations:
                await _courseService.ArchiveCourseRunsByUKPRN(UKPRN);

                return(View("../Migration/DeleteConfirmed/Index"));

            case MigrationDeleteOptions.Cancel:
                return(RedirectToAction("Index", "PublishCourses", new { publishMode = PublishMode.Migration }));

            default:
                return(RedirectToAction("index"));
            }
        }
Beispiel #25
0
        public ActionResult Delete(DeleteViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var journals = this.journalRepository.All;
                var issns    = GetISSNs(model);

                var journalsISSNs = journals.Select(j => j.ISSN).ToSet(StringComparer.InvariantCultureIgnoreCase);
                var issnsFound    = issns.Intersect(journalsISSNs).ToList();
                var issnsNotFound = issns.Except(journalsISSNs).ToList();

                var journalsToDelete = journals.Where(j => issnsFound.Contains(j.ISSN)).ToList();
                foreach (var journal in journalsToDelete)
                {
                    this.journalRepository.Delete(journal);
                }
                this.journalRepository.Save();

                this.Session[FoundISSNsSessionKey]    = issnsFound;
                this.Session[NotFoundISSNsSessionKey] = issnsNotFound;

                return(this.RedirectToAction("Deleted"));
            }

            return(this.View(model));
        }
        public void Delete_GET_passes_correct_book_and_searchSortPageParams_to_view()
        {
            // Arrange
            string searchString           = "H3J";
            string sortCol                = "name";
            string nextOrder              = SearchSortPageViewModel.SORT_ORDER_ASC;
            string currentOrder           = SearchSortPageViewModel.SORT_ORDER_ASC;
            int    page                   = 1;
            int    pageSize               = 5;
            int    id                     = 1;
            SearchSortPageViewModel sspVM = new SearchSortPageViewModel(searchString, sortCol, currentOrder, nextOrder, page, pageSize);
            RecordViewModel         rVM   = new RecordViewModel(sspVM, id);


            // Act
            ViewResult      result   = controller.Delete(rVM) as ViewResult;
            DeleteViewModel deleteVM = (DeleteViewModel)result.ViewData.Model;

            // Assert
            Assert.IsNotNull(result);

            Assert.AreEqual(id, deleteVM.Book.ID);
            Assert.AreEqual("BBB", deleteVM.Book.Name);

            Assert.IsNotNull(deleteVM.SearchSortPageParams);
            Assert.AreEqual(searchString, deleteVM.SearchSortPageParams.SearchString);
            Assert.AreEqual(sortCol, deleteVM.SearchSortPageParams.SortCol);
            Assert.AreEqual(nextOrder, deleteVM.SearchSortPageParams.NextOrder);
            Assert.AreEqual(page, deleteVM.SearchSortPageParams.Page);
            Assert.AreEqual(pageSize, deleteVM.SearchSortPageParams.PageSize);
        }
        public async Task<ActionResult> Index(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            Guid? notificationId;

            if (model.IsExportNotification.GetValueOrDefault())
            {
                notificationId = await mediator.SendAsync(new GetNotificationIdByNumber(model.NotificationNumber));
            }
            else
            {
                notificationId = await mediator.SendAsync(new GetImportNotificationIdByNumber(model.NotificationNumber));
            }

            if (notificationId == null)
            {
                ModelState.AddModelError("NotificationNumber", DeleteNotificationControllerResources.NumberNotExist);

                return View(model);
            }

            var deleteModel = new DeleteViewModel(model, notificationId.GetValueOrDefault());

            return RedirectToAction("Check", deleteModel);
        }
Beispiel #28
0
        public async Task <IActionResult> Delete([FromBody] DeleteViewModel model)
        {
            if (model.Id <= 0)
            {
                return(BadRequest());
            }

            var modelo = await _context.SalesStates.FirstOrDefaultAsync(x => x.Id == model.Id);

            modelo.Enabled = false;



            _context.Entry(modelo).State = EntityState.Modified;

            if (modelo == null)
            {
                return(NotFound());
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                //Guardar Exception
                return(BadRequest());
            }

            return(Ok());
        }
Beispiel #29
0
        public ActionResult Delete(DeleteViewModel vmDelete)
        {
            try
            {
                // transfer vm to dto
                var dtoAsset = _unitOfWork.Assets.Get(vmDelete.Id);
                if (dtoAsset != null)
                {
                    dtoAsset.IsActive = false;

                    // update db
                    _unitOfWork.CommitTrans();

                    // display view with message
                    TempData["SuccessMessage"] = "Record Deleted";
                    return(RedirectToAction("Index", "Asset"));
                }
                TempData["ErrorMessage"] = "Unable to delete record. Try again.";
                return(RedirectToAction("Index", "Asset"));
            }
            catch (Exception)
            {
                TempData["ErrorMessage"] = "Encountered problem";
                return(RedirectToAction("Index", "Asset"));
            }
        }
Beispiel #30
0
        public async Task <ActionResult> Delete(Guid id, DeleteViewModel model)
        {
            var movementId = await mediator.SendAsync(new GetMovementIdIfExists(id, model.Number.Value));

            bool result = false;

            if (movementId.HasValue)
            {
                result = await mediator.SendAsync(new DeleteMovement(movementId.Value));

                await this.auditService.AddMovementAudit(this.mediator,
                                                         id, model.Number.Value,
                                                         User.GetUserId(),
                                                         MovementAuditType.Deleted);
            }

            var confirmModel = new ConfirmViewModel
            {
                Number         = model.Number,
                Success        = result,
                NotificationId = id
            };

            return(RedirectToAction("Confirm", confirmModel));
        }
Beispiel #31
0
        public IActionResult Delete(int id)
        {
            var data   = _classifyService.Get(id);
            var result = DeleteViewModel.Convert(data.Id, data.Content);

            return(View("_Delete", result));
        }
        public async Task<ActionResult> Delete(Guid id, DeleteViewModel model)
        {
            var movementId = await mediator.SendAsync(new GetImportMovementIdIfExists(id, model.Number.Value));
            bool result = false;

            if (movementId.HasValue)
            {
                result = await mediator.SendAsync(new DeleteMovement(movementId.Value));
            }

            var confirmModel = new ConfirmViewModel
            {
                Number = model.Number,
                Success = result,
                NotificationId = id
            };

            return RedirectToAction("Confirm", confirmModel);
        }
        public ActionResult Delete(DeleteViewModel model)
        {
            // Actually delete the notification

            return View("Confirm", model);
        }
 public ActionResult Check(DeleteViewModel model)
 {
     return View(model);
 }
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                throw new HttpException(400, "Bad Request");
            }

            var documentCategory = DocumentCategoryService.FindById(id.Value);
            if (documentCategory == null)
            {
                throw new HttpException(404, "Not Found");
            }
            var deleteViewModel = new DeleteViewModel()
            {
                DocumentCategoryId = documentCategory.DocumentCategoryId,
                Name = documentCategory.Name,
                Description = documentCategory.Description
            };
            return View(deleteViewModel);
        }