Esempio n. 1
0
 public IActionResult Put(string id, Authour model)
 {
     try
     {
         var Authour = _repo.UpdatePutAuthour(id, model);
         return(new OkObjectResult(new{ message = "Authour updated succesfully", id }));
     }
     catch (Exception e)
     {
         return(BadRequest(new { message = e.Message }));
     }
 }
Esempio n. 2
0
 public IActionResult Post(Authour model)
 {
     try
     {
         var Authour = _repo.AddAuthour(model);
         return(new CreatedResult("/Authour/", new { Id = Authour.Id, message = "Authour created succesfully" }));
     }
     catch (Exception e)
     {
         return(BadRequest(new { message = e.Message }));
     }
 }
Esempio n. 3
0
        public Authour UpdatePutAuthour(string id, Authour model)
        {
            var Authour = GetOneAuthour(id);

            if (Authour is null)
            {
                throw new ArgumentOutOfRangeException(message: "No Authour with this Id found", null);
            }

            Authour.FullName = model.FullName;

            _context.Authour.Update(Authour);
            _context.SaveChanges();
            return(Authour);
        }
Esempio n. 4
0
        public Authour AddAuthour(Authour model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(message: "Authour cannot be null", null);
            }

            var Authour = new Authour
            {
                Id       = Guid.NewGuid().ToString(),
                FullName = model.FullName
            };

            _context.Authour.Add(Authour);
            _context.SaveChanges();
            return(Authour);
        }