public virtual IActionResult Update(Guid id, [FromBody] VM vm)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest());
            }
            //

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var find = Service.Find(id);

            if (find == null)
            {
                return(NotFound());
            }
            //
            T model;

            try
            {
                model = _mapper.Map <T>(vm);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Exception", e.Message);
                return(BadRequest(ModelState));
            }

            var result = Service.Update(model);

            if (!result.Success)
            {
                ModelState.AddErrorFromResult(result.Messages);
                return(BadRequest(ModelState));
            }
            if (!Service.Save())
            {
                ModelState.AddModelError("NotSave", "Something was wrong on server while saving");
                return(StatusCode(500, ModelState));
            }
            return(NoContent());
        }
        public virtual IActionResult Patch(Guid id, [FromBody] JsonPatchDocument <VM> vm)
        {
            if (id == Guid.Empty || vm == null)
            {
                return(BadRequest());
            }

            var find = Service.Find(id);

            if (find == null)
            {
                return(NotFound());
            }

            var toPatch = _mapper.Map <VM>(find);

            vm.ApplyTo(toPatch, ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var model = _mapper.Map <T>(toPatch);

            var result = Service.Update(model);

            if (!result.Success)
            {
                ModelState.AddErrorFromResult(result.Messages);
                return(BadRequest(ModelState));
            }
            if (!Service.Save())
            {
                ModelState.AddModelError("NotSave", "Something was wrong on server while saving");
                return(StatusCode(500, ModelState));
            }

            return(NoContent());
        }
        public virtual IActionResult Create([FromBody] VM vm)
        {
            if (vm == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            T model;

            try
            {
                model = _mapper.Map <T>(vm);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("Exception", e.Message);
                return(BadRequest(ModelState));
            }
            var result = Service.Add(model);

            if (!result.Success)
            {
                ModelState.AddErrorFromResult(result.Messages);
                return(BadRequest(ModelState));
            }
            if (!Service.Save())
            {
                ModelState.AddModelError("NotSave", "Something was wrong on server while saving");
                return(StatusCode(500, ModelState));
            }

            return(Created(Request.Path + "/" + model.Id, model));
        }