Exemplo n.º 1
0
        public IActionResult Add(int customerId, [FromBody] ContactFormDto contactDto)
        {
            var contact = _contactAppService.Add(customerId, contactDto);

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

            return(StatusCode(StatusCodes.Status201Created, contact));
        }
Exemplo n.º 2
0
        public JsonResult Create(ContactViewModel objContact)
        {
            try
            {
                var contact = Mapper.Map <ContactViewModel, Contact>(objContact);
                _contactApp.Add(contact);

                return(Json(new { success = true, responseText = "Salvo com sucesso." }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, responseText = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <IActionResult> Save([FromBody] ContactViewModel model)
        {
            ContactViewModel result;

            try
            {
                if (model.Id == 0)
                {
                    result = await Task.FromResult(_service.Add(model.MapTo <Contact>()));
                }
                else
                {
                    result = await Task.FromResult(_service.Update(model.MapTo <Contact>()));
                }
                return(Ok(result.MapTo <ContactViewModel>()));
            }
            catch (Exception e)
            {
                return(BadRequest($"Error while saving Contact {e.Message}"));
            }
        }
Exemplo n.º 4
0
 public ContactViewModel Post([FromBody] ContactViewModel contact)
 {
     contact = _contactAppService.Add(contact);
     contact.AddRangeLink(_contactEnricher.CreateLinks(Method.Post, contact));
     return(contact);
 }