示例#1
0
        public IActionResult Patch(string id, [FromBody] JsonPatchDocument <ClientDet> clientDetPatch)
        {
            try
            {
                if (Guid.TryParse(id, out Guid parsedId))
                {
                    //var userId = User.FindFirstValue("sub");

                    ClientDetail clientDetail = _unitOfWork.ClientDetails.Get(parsedId);

                    ClientDet clientDet = _mapper.Map <ClientDet>(clientDetail);

                    clientDetPatch.ApplyTo(clientDet);

                    _mapper.Map(clientDet, clientDetail);

                    _unitOfWork.Complete();

                    return(CreatedAtRoute("Get", new { id = _mapper.Map <ClientDet>(clientDetail).Id }, _mapper.Map <ClientDet>(clientDetail)));
                }
            }
            catch (Exception e)
            {
                string message = e.Message;
            }

            return(BadRequest());
        }
示例#2
0
        public IActionResult Post([FromBody] ClientDet clientDet)
        {
            try
            {
                if (clientDet.Id == Guid.Empty)
                {
                    ClientHeader clientHeader = _unitOfWork.ClientHeaders.SingleOrDefault(c => c.Id == clientDet.ClientHeaderId, true);

                    if (clientHeader.Id != Guid.Empty)
                    {
                        //var userId = User.FindFirstValue("sub");

                        var clientDetail = _mapper.Map <ClientDetail>(clientDet);

                        _unitOfWork.ClientDetails.Add(clientDetail);

                        _unitOfWork.Complete();

                        return(Created(new Uri($"{Request.Path}/{clientDetail.Id}", UriKind.Relative), _mapper.Map <ClientDet>(clientDetail)));
                    }
                }
            }
            catch (Exception e)
            {
                string message = e.Message;
            }

            return(BadRequest());
        }