Пример #1
0
 public async Task <ActionResult <SamuraiModel> > Post(SamuraiModel model)
 {
     try
     {
         var location = linkGenerator.GetPathByAction("Get", "Samurai", new { model.Id });
         var samurai  = mapper.Map <Samurai>(model);
         samuraiData.Add(samurai);
         if (await samuraiData.SaveChangesAsync())
         {
             return(Created(location, mapper.Map <SamuraiModel>(samurai)));
         }
     }
     catch (Exception)
     {
         return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failiure"));
     }
     return(BadRequest());
 }
Пример #2
0
        public async Task <ActionResult <QuoteModel> > Post(int samuraiId, QuoteModel model)
        {
            try
            {
                var samurai = await samuraiData.GetSamuraiByIdAsync(samuraiId);

                var quote = mapper.Map <Quote>(model);

                quote.Samurai = samurai;
                samuraiData.Add(quote);
                if (await samuraiData.SaveChangesAsync())
                {
                    var url = linkGenerator.GetPathByAction(HttpContext, "Get", values: new { samuraiId, id = quote.Id });
                    return(Created(url, mapper.Map <QuoteModel>(quote)));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failiure"));
            }
            return(BadRequest());
        }