public IActionResult Create(CreateAlbumViewModel model)
 {
     if (int.TryParse(model.SingerId, out int singerId))
     {
         var album = new AlbumModel()
         {
             Name      = model.Name.Trim(),
             SingerId  = singerId,
             CreatorId = HttpContext.Session.GetCurrentUserId()
         };
         album = _albumAppService.Create(album);
         return(Json(new JsonResultEntity()
         {
             Message = "添加专辑成功!",
             JsonObject = Json(new AlbumViewModel()
             {
                 Id = album.Id,
                 SingerId = album.SingerId,
                 CreatorId = album.CreatorId,
                 Name = album.Name,
                 SingerName = album.SingerName,
                 CreatorName = album.CreatorName,
                 CreationTime = album.CreationTime.ToStandardDateOfChina(),
             })
         }));
     }
     else
     {
         throw new JMBasicException("歌唱家不存在");
     }
 }
Exemplo n.º 2
0
 public IActionResult Post([FromBody] AlbumInsertingModel model)
 {
     try
     {
         return(StatusCode(201, App.Create(model)));
     }
     catch (ValidationException ex)
     {
         return(StatusCode(400, ex.ToString()));
     }
     catch (InternalServerException ex)
     {
         return(StatusCode(500, ex.ToString()));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.ToString()));
     }
 }
Exemplo n.º 3
0
        public ActionResult Create(Album album)
        {
            if (ModelState.IsValid)
            {
                var validationResult = _albumAppService.Create(album);

                if (validationResult.IsValid)
                {
                    return(RedirectToAction("Index"));
                }

                foreach (var error in validationResult.Errors)
                {
                    ModelState.AddModelError("", error.Message);
                }
            }

            ViewBag.GenreId  = new SelectList(_genreAppService.All(@readonly: true), "GenreId", "Name", album.GenreId);
            ViewBag.ArtistId = new SelectList(_artistAppService.All(@readonly: true), "ArtistId", "Name", album.ArtistId);
            return(View(album));
        }