Пример #1
0
        public virtual HttpResponseMessage Post([FromBody] TEntity entityObj)
        {
            HttpResponseMessage result = null;

            try
            {
                //Prevents addition of unwanted data nested objects are removed.
                //It's a security task too, it prevents addition of related objects through a parent obj
                entityObj = entityObj.Map().ToObject <TEntity>();

                if (!ModelState.IsValid)
                {
                    result = JsonResponse.Response(BadRequest(ModelState), Request);
                }
                else
                {
                    if (baseLogic.Create(entityObj))
                    {
                        result = Ok(entityObj.Map(true));
                    }
                    else
                    {
                        result = JsonResponse.Response(InternalServerError(), Request);
                    }
                }
            }
            catch (Exception ex)
            {
                result = ProccessException(ex);
            }

            return(result);
        }