Beispiel #1
0
        public IHttpActionResult  NewQuestionComment([FromBody] QuestionComment qc)
        {
            //var user = await _repository.GetUserByEmailAsync(User.Identity.Name);

            //if (user != null)
            //    qc.UserId = user.UserId;
            //else
            //    qc.UserId = new Guid("00000000-0000-0000-0000-000000000000");
            //to do   alert user not found

            //qc.User = user;

            qc.UpdateDate = DateTime.Now;
            Repository.Entities.User user = _repository.GetUserByUserName(User.Identity.Name);
            if (user != null)
            {
                qc.UserId = user.UserId;
            }
            else
            {
                qc.UserId = new Guid("0e5f76d4-7180-44e9-bc34-ced22a6d2bed");
            }

            Question questionSource = _repository.GetQuestion(qc.QuestionSource.Id);

            qc.QuestionSource = questionSource;
            RepositoryActionResult <QuestionComment> result = _repository.AddQuestionComment(qc);

            switch (result.Status)
            {
            case RepositoryActionStatus.Created:
            {
                int    newID       = result.Entity.Id;
                String UserName    = result.Entity.QuestionSource.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));
        }