public async Task <bool> UpdateAsync(GroupWriteViewModel model, string slug, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(slug)) { throw new ArgumentNullException(nameof(slug)); } if (model is null) { throw new ArgumentNullException(nameof(model)); } return(await _groupCommand.UpdateAsync(model, slug, cancellationToken)); }
public async Task <bool> UpdateAsync(GroupWriteViewModel model, string slug, CancellationToken cancellationToken = default) { if (model is null) { throw new ArgumentNullException(nameof(model)); } if (string.IsNullOrWhiteSpace(slug)) { throw new ArgumentNullException(nameof(slug)); } var sql = @"UPDATE [dbo].[Group] SET [Name] = @name, [Description] = @description, [Image] = @image, [PublicGroup] = @publicGroup, [Introduction] = @introduction, [AboutUs] = @aboutUs WHERE [Slug] = @slug"; var param = new { name = model.Name, description = model.Description, image = model.Image, publicGroup = model.PublicGroup, introduction = model.Introduction, aboutUs = model.AboutUs, slug = slug }; using (var conn = _connectionFactory.CreateWriteOnlyConnection()) { if (await conn.ExecuteAsync(sql, param) == 1) { return(true); } return(false); } }
public async Task <ActionResult> EditAsync(GroupWriteViewModel model, string slug, CancellationToken cancellationToken = default(CancellationToken)) { if (model is null) { throw new ArgumentNullException(nameof(model)); } if (string.IsNullOrWhiteSpace(slug)) { throw new ArgumentNullException(nameof(slug)); } if (this.ModelState.IsValid) { if (!_groupService.UserIsAdmin(slug, LoggedOnReadOnlyUser.Id)) { return(new HttpUnauthorizedResult()); } if (model.Files != null) { var uploadResult = _groupService.UploadGroupImage(model.Files, model.Id); if (uploadResult.UploadSuccessful) { model.Image = uploadResult.UploadedFileName; } else { ModelState.AddModelError(nameof(model.Files), "Failed to upload file"); } } if (ModelState.IsValid && await _groupService.UpdateAsync(model, slug, cancellationToken)) { return(RedirectToAction("Show", "Group", new { slug, tab = String.Empty })); } } return(View(model)); }
public async Task <ActionResult> EditAsync(string slug, string tab, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(slug)) { throw new ArgumentNullException(nameof(slug)); } if (string.IsNullOrWhiteSpace(tab)) { throw new ArgumentNullException(nameof(tab)); } if (!_groupService.UserIsAdmin(slug, LoggedOnReadOnlyUser.Id)) { return(new HttpUnauthorizedResult()); } var group = await _groupService.GetAsync(slug, cancellationToken); if (group is null) { return(HttpNotFound()); } var model = new GroupWriteViewModel { Id = group.Id, Description = group.Description, Image = group.Image, Introduction = group.Introduction, AboutUs = group.AboutUs, Name = group.Name, PublicGroup = group.PublicGroup, Slug = group.Slug, }; return(View(model)); }
public void SetUp() { _groupWriteViewModel = new GroupWriteViewModel { Name = GROUP_NAME, Description = GROUP_DESCRIPTION, Introduction = GROUP_INTRODUCTION, Image = GROUP_IMAGE, PublicGroup = true, }; _groupViewModel = new GroupViewModel { Name = GROUP_NAME, Description = GROUP_DESCRIPTION, Introduction = GROUP_INTRODUCTION, Image = GROUP_IMAGE, PublicGroup = true, }; _groupService = new GroupService( _context.Object, _roleService.Object, _notificationService.Object, _groupPermissionForRoleService.Object, _cacheService.Object, _groupRepository.Object, _localizationService.Object, _groupCommand.Object, _imageService.Object, _imageCommand.Object, _imageRepository.Object ); _postedFile = new Mock <HttpPostedFileBase>(); }