public HttpResponse Create(CreateAlbumInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Length < 4 || input.Name.Length > 20) { return(this.Redirect("/Albums/Create")); } if (string.IsNullOrWhiteSpace(input.Cover)) { return(this.Redirect("/Albums/Create")); } if (!Uri.TryCreate(input.Cover, UriKind.Absolute, out _)) { return(this.Redirect("/Albums/Create")); } this.albumsService.CreateAlbum(input.Name, input.Cover); return(this.Redirect("/Albums/All")); }
public void Create(CreateAlbumInputModel model) { var album = new Album() { Cover = model.Cover, Name = model.Name }; this.data.Albums.Add(album); this.data.SaveChanges(); }
public void Create(CreateAlbumInputModel model) { var album = new Album { Name = model.Name, Cover = model.Cover, Price = 0M }; this.dbContext.Albums.Add(album); this.dbContext.SaveChanges(); }
public async Task CreateAlbumAsync(CreateAlbumInputModel createAlbum) { Album album = new Album { Id = Guid.NewGuid().ToString(), Name = createAlbum.Name, Cover = createAlbum.Cover, }; await this.albumRepository.AddAsync(album); await this.albumRepository.SaveChangesAsync(); }
public async Task CreateAsync(CreateAlbumInputModel model, string userId) { var album = new Album { Name = model.Name, Description = model.Description, IsPrivate = model.IsPrivate, OwnerId = userId, }; await this.albumsRespository.AddAsync(album); await this.albumsRespository.SaveChangesAsync(); }
public void Create_ShouldCreateAlbumSuccessfully() { var list = new List <Album>(); var model = new CreateAlbumInputModel() { Description = "TestDesc", IsPrivate = false, Name = "testName" }; var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>()); var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(list); var services = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object); services.CreateAsync(model, "testUser").Wait(); Assert.Single(list); }
public async Task <IActionResult> Create(CreateAlbumInputModel model) { try { if (this.ModelState.IsValid) { string albumId = await this.albumService.CreateAsync(model.Title, CurrentUser); if (string.IsNullOrEmpty(albumId)) { AddDangerNotification(string.Format(Notifications.CreatedFail, model.Title)); return(Redirect("/Albums")); } logger.LogInformation( string.Format(SetLog.CreatedSuccess, CurrentUser.UserName, CurrentController, albumId )); AddWarningNotification(string.Format(Notifications.CreatedSuccess, model.Title)); return(Redirect($"/Albums/Update/{albumId}")); } else { logger.LogInformation(string.Format(SetLog.CreatedFail, CurrentUser.UserName, CurrentController)); AddDangerNotification(string.Format(Notifications.CreatedFail, model.Title)); return(View(model)); } } catch (System.Exception e) { logger.LogError(string.Format(SetLog.Error, CurrentUser.UserName, CurrentController, e.Message)); AddDangerNotification(string.Format(Notifications.Fail)); return(Redirect("/Albums")); } }
public HttpResponse Create(CreateAlbumInputModel model) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (model.Name.Length < 4 || model.Name.Length > 20) { return(this.Error("Name should be between [4-20] characters.")); } if (String.IsNullOrEmpty(model.Cover)) { return(this.Error("Cover is required.")); } this.albumsService.Create(model); return(this.Redirect("/Albums/All")); }
public async Task <IActionResult> Create(CreateAlbumInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var user = await this.userManager.GetUserAsync(this.User); try { await this.albumsService.CreateAsync(model, user.Id); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); return(this.View(model)); } return(this.View("CreateSuccessful")); }
public HttpResponse Create(CreateAlbumInputModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (input.Name.Length < 4 || input.Name.Length > 20) { return(this.Redirect("/Albums/Create")); } if (String.IsNullOrWhiteSpace(input.Cover)) { return(this.Redirect("/Albums/Create")); } this.albumsService.Create(input.Name, input.Cover); return(this.Redirect("/Albums/All")); }
public HttpResponse Create(CreateAlbumInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (inputModel.Name.Length < 4 || inputModel.Name.Length > 20) { return(this.Error("Name should be with length between 4 and 20")); //return this.View(); } if (string.IsNullOrWhiteSpace(inputModel.Cover)) { return(this.Error("Cover is required.")); //return this.View(); } this.albumsService.CreateAlbum(inputModel.Name, inputModel.Cover); return(this.Redirect("/Albums/All")); }
public HttpResponse Create(CreateAlbumInputModel model) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (model.Name.Length < 4 || model.Name.Length > 20) { return(this.Error("Album name should be between 4 and 20 characters.")); } if (string.IsNullOrEmpty(model.Cover) || string.IsNullOrWhiteSpace(model.Cover) || string.IsNullOrWhiteSpace(model.Name) || string.IsNullOrEmpty(model.Name)) { return(this.Redirect("/Albums/Create")); } albumsService.Create(model); return(this.Redirect("All")); }
public async Task <IActionResult> Create(CreateAlbumInputModel createAlbum) { await this.albumService.CreateAlbumAsync(createAlbum); return(this.Redirect("/Albums/All")); }
public IViewComponentResult Invoke() { var model = new CreateAlbumInputModel(); return(View(model)); }
public IActionResult Create() { var viewModel = new CreateAlbumInputModel(); return(this.View(viewModel)); }