示例#1
0
        public async Task <IActionResult> Update(string id, PubModel model)
        {
            try
            {
                var user = await _hexadoUserService.GetSingleOrMaybeAsync(u => u.Email == UserEmail);

                if (!user.HasValue)
                {
                    return(Unauthorized());
                }

                var result = await _pubService.UpdateAsync(
                    model.ToEntity(
                        user.Value.Account.Id,
                        id));

                return(result.HasValue
                    ? OkJson(result.Value.ToResponse())
                    : NotFound());
            }
            catch (UserNotAllowedToUpdatePubException ex)
            {
                _logger.LogWarning(ex, $"User: {UserEmail} not allowed to update pubId: {id}!");
                return(ForbiddenJson());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error while updating pub! " +
                                 $"Id: {id}");
                return(InternalServerErrorJson(ex));
            }
        }
示例#2
0
 public IActionResult Put(int id, [FromBody] PubModel pubModel)
 {
     try
     {
         Pub pub = pubModel.ToEntity();
         pub.Id = id;
         logic.Update(pub);
         return(Ok());
     }
     catch (Exception e)
     {
         return(NotFound(e.Message));
     }
 }
示例#3
0
        public async Task <IActionResult> Create(PubModel model)
        {
            try
            {
                var user = await _hexadoUserService.GetSingleOrMaybeAsync(u => u.Email == UserEmail);

                if (!user.HasValue)
                {
                    return(Unauthorized());
                }

                var result = await _pubService.CreateAsync(model.ToEntity(user.Value.Account.Id));

                return(result.HasValue
                    ? CreatedJson(result.Value.ToResponse())
                    : BadRequest());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error while creating new pub!");
                return(InternalServerErrorJson(ex));
            }
        }
示例#4
0
 public static Pub ToEntity(this PubModel model, string accountId)
 {
     return(model.ToEntity(accountId, default));
 }
示例#5
0
        public IActionResult Post(PubModel pub)
        {
            Pub newPub = logic.Add(pub.ToEntity());

            return(Ok(newPub));
        }