public async Task <IActionResult> Create(AlbumCreateInputModel input) { var groups = await this.groupsService.GetAll <GroupDropDownViewModel>().ToListAsync(); if (!this.ModelState.IsValid) { input.Groups = groups; return(this.View(input)); } try { var id = await this.albumsService .CreateAsync(input.Name, input.CoverUrl, input.ReleaseDate, input.GroupId); this.TempData["Success"] = CreateSuccessMessage; return(this.Redirect("/Groups/Details/" + input.GroupId)); } catch (Exception e) { this.TempData["Error"] = e.Message; input.Groups = groups; return(this.View(input)); } }
public async Task <IActionResult> Create(AlbumCreateInputModel inputModel) { if (ModelState.IsValid) { var profileId = _userManager.GetProfileId(User); await _albumService.CreateAlbum(profileId, inputModel.Title, inputModel.Description, inputModel.Picture); return(RedirectToAction("Albums", "Profile")); } return(View(inputModel)); }
public IActionResult Create(AlbumCreateInputModel model) { if (!ModelState.IsValid) { return(this.Redirect("/Albums/Create")); } Album album = ModelMapper.ProjectTo <Album>(model); this.albumService.CreateAlbum(album); return(this.Redirect("/Albums/All")); }
public async Task <IActionResult> Create(int?id = null) { var groups = await this.groupsService.GetAll <GroupDropDownViewModel>().ToListAsync(); var viewModel = new AlbumCreateInputModel { Groups = groups, }; this.TempData["groupId"] = id; return(this.View(viewModel)); }
public IActionResult Create(AlbumCreateInputModel model) { if (!ModelState.IsValid) { return(Redirect("/Albums/Create")); } Album album = model.MapTo <Album>(); albumService.CreateAlbum(album); return(Redirect("/Albums/All")); }
public ActionResult Create(AlbumCreateInputModel inputModel) { //this is the modelValidation in THE CONTROLLER, not the one in the csHtml! if (!ModelState.IsValid) { return(this.Redirect("/Albums/Create")); } Album album = new Album { Name = inputModel.Name, Cover = inputModel.Cover, Price = 0M }; this.albumService.CreateAlbum(album); return(this.Redirect("/Albums/All")); }
public HttpResponse Create(AlbumCreateInputModel model) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (model.Name.Length < 4 || model.Name.Length > 20) { return(this.Error("Password must be at least 4 characters and at most 20")); } if (string.IsNullOrWhiteSpace(model.Cover)) { return(this.Error("Cover cannot be empty!")); } this.albumsService.CreateAlbum(model.Name, model.Cover); return(this.Redirect("/Albums/All")); }
public HttpResponse Create(AlbumCreateInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(inputModel.Cover)) { return(this.Error("Cover is required!")); } if (inputModel.Name.Length < 6 || inputModel.Name.Length > 20) { return(this.Error("Name must be at least 6 characters and at most 20")); } this.albumsService.Create(inputModel.Name, inputModel.Cover); return(this.Redirect("/Albums/All")); }