Beispiel #1
0
 public async Task <ActionResult <Product> > CreateProduct([FromBody] Product product)
 {
     try
     {
         if (!await User.IsPlaceProviderAdmin(userRepository, placeProviderRepository))
         {
             throw new Exception(localizer[Resources.Controllers_AdminController.Only_admin_is_allowed_to_invite_other_users].Value);
         }
         product.Id         = Guid.NewGuid().ToString();
         product.CreatedOn  = DateTimeOffset.Now;
         product.LastUpdate = product.CreatedOn;
         return(Ok(await placeProviderRepository.AddProduct(User.GetPlaceProvider(), product)));
     }
     catch (ArgumentException exc)
     {
         logger.LogError(exc.Message);
         return(BadRequest(new ProblemDetails()
         {
             Detail = exc.Message
         }));
     }
     catch (Exception exc)
     {
         logger.LogError(exc, exc.Message);
         return(BadRequest(new ProblemDetails()
         {
             Detail = exc.Message
         }));
     }
 }