Esempio n. 1
0
        public IHttpActionResult NewAnswerComment([FromBody] AnswerComment ac)
        {
            ac.UpdateDate = DateTime.Now;
            Repository.Entities.User user = _repository.GetUserByUserName(User.Identity.Name);
            if (user != null)
            {
                ac.UserId   = user.UserId;
                ac.NickName = user.NickName;
            }
            else
            {
                ac.UserId = new Guid("0e5f76d4-7180-44e9-bc34-ced22a6d2bed");
            }

            Answer answerSource = _repository.GetAnswer(ac.AnswerSource.Id);

            ac.AnswerSource = answerSource;
            RepositoryActionResult <AnswerComment> result = _repository.AddAnswerComment(ac);

            switch (result.Status)
            {
            case RepositoryActionStatus.Created:
            {
                int    newID       = result.Entity.Id;
                String UserName    = result.Entity.AnswerSource.UserName;
                String UserId      = result.Entity.UserId.ToString();
                String Description = result.Entity.Description;
                String UpdateDate  = result.Entity.UpdateDate.HasValue ? result.Entity.UpdateDate.Value.ToShortDateString() : "";
                return(Content(System.Net.HttpStatusCode.OK, newID + "*" + UserName + "*" + UserId + "*" + Description + "*" + UpdateDate));
            }

            case RepositoryActionStatus.NothingModified:
                return(Content(System.Net.HttpStatusCode.OK, "Risultato Not Modified?"));    //TODO have I to return OK?

            case RepositoryActionStatus.Error:
                return(Content(System.Net.HttpStatusCode.InternalServerError, result.Exception.InnerException.Message));

            default:
                break;
            }
            return(Content(System.Net.HttpStatusCode.Ambiguous, result.Status.ToString() + "  " + result.Entity.Description));
        }