Ejemplo n.º 1
0
        public async Task <ClientDto> Add(ClientDto clientDto)
        {
            try
            {
                var client = _mapper.Map <Client>(clientDto);
                var result = await _serviceClient.Add(client);

                return(_mapper.Map <ClientDto>(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Create(ClientViewModel collection)
        {
            Customer cust = new Customer();

            cust.type        = collection.type;
            cust.description = collection.description;
            cust.category    = collection.category;
            cust.speciality  = collection.speciality;


            service.Add(cust);

            service.Commit();
            return(RedirectToAction("Index"));
        }
        public virtual JsonResult Create()
        {
            var entity = Request.GetPostData();

            try
            {
                if (!ModelState.IsValid)
                {
                    var sb     = new StringBuilder(@"<p>Please correct the following errors:</p><ul>");
                    var errors = ModelState.Values.SelectMany(v => v.Errors);
                    foreach (var err in errors)
                    {
                        sb.AppendFormat("<li>{0}</li>", err.ErrorMessage);
                    }
                    sb.Append("</ul>");
                    return(Json(new { Result = "ERROR", Message = sb.ToString() }));
                }

                var request = new AddOrUpdateRequest {
                    Entities = new dynamic[] { entity }
                };
                var response = _repository.Add <AddOrUpdateRequest, AddOrUpdateResponse>(request);
                return(Json(new { Result = "OK", Record = response.Result[0] }));
            }
            catch (InvalidOperationException ex)
            {
                return(Json(new
                {
                    Result = "ERROR",
                    Message = String.Format("{0}<br/>Details:{1}", ex.Message, ex.Data["DetailHtml"])
                }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Result = "ERROR",
                    Message = ex.Message
                }));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] RequestClient client)
        {
            try
            {
                client.Id = Guid.NewGuid();

                if (await _serviceClient.Add(_mapper.Map <Client>(client)))
                {
                    return(Ok(new ResponseAdded()
                    {
                        Id = client.Id
                    }));
                }

                return(BadRequest(new FailResponse($"Erro ao cadastrar.")));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new FailResponse(e.Message, e)));
            }
        }
Ejemplo n.º 5
0
        public void Add(ClientDto clientDto)
        {
            var client = mapper.Map <Client>(clientDto);

            serviceClient.Add(client);
        }
Ejemplo n.º 6
0
        public void Add(ClientDto clientDto)
        {
            var client = mapperClient.MapperDtoToEntity(clientDto);

            serviceClient.Add(client);
        }
        public void Add(ClientDTO clientDTO)
        {
            var client = mapperClient.MapperDTOToEntity(clientDTO);

            serviceClient.Add(client);
        }
Ejemplo n.º 8
0
        public void Add(ClientDTO obj)
        {
            var objClient = _mapperClient.MapperToEntity(obj);

            _serviceClient.Add(objClient);
        }