Exemplo n.º 1
0
 public ActionResult <Model.Album> Create([FromBody] Model.RawAlbum value)
 {
     try
     {
         var created = repository.Create(value);
         return(CreatedAtAction(nameof(GetDetails), new { name = created.Name, owner = created.Owner }, created));
     } catch (ArgumentException e)
     {
         return(BadRequest(new { error = e.Message }));
     }
 }
Exemplo n.º 2
0
        public Model.Album Create(Model.RawAlbum value)
        {
            var album = FindByNameAndOwner(value.Name, value.Owner);

            if (album == null)
            {
                var toInsert = toEntityFromRaw(value);
                albumCollection.InsertOne(toInsert);
                return(toModel(FindByNameAndOwner(toInsert.AlbumName, toInsert.Owner)));
            }
            else
            {
                throw new ArgumentException("This user already has an album under that name");
            }
        }