Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] AddContactModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(GetModelErrors(ModelState)));
            }
            try
            {
                var contact = new Contact
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Mobile    = model.Mobile,
                    Email     = model.Email,
                    Age       = model.Age,
                    TenantId  = this.TenantId
                };
                await _contactService.AddContactAsync(contact);

                return(Ok(model));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
        public async Task <IActionResult> AddContact(PeopleViewModel model) // Adding new contact Save
        {
            //return Json(model);

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

            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var successful = await _contactServices.AddContactAsync(model, currentUser.Id);

            //return Json(currentUser);
            if (successful)
            {
                return(Redirect("Index"));
            }

            return(BadRequest(new { error = "Could not add new Contact." }));
        }
        public async Task <ActionResult <Contact> > AddContactAsync(ContactDto contactDto)
        {
            if (ModelState.IsValid)
            {
                var contact = await _contactService.AddContactAsync(contactDto);

                return(CreatedAtAction("GetContact", new { id = contact.ContactId }, contact));
            }
            return(BadRequest());
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> AddContactAsync([FromBody] ContactModel contactModel)
        {
            if (!ModelStateValid(ModelState, out var badRequest))
            {
                return(badRequest);
            }

            var contact = MapContactModelToContactEntity(contactModel, status: "Inactive");
            await _contactService.AddContactAsync(contact);

            return(Created(Request?.RequestUri.ToString() ?? "/", contact));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <Order> > AddContact([FromBody] ContactRequest request)
        {
            var userID = HttpContext.GetUserId();

            var result = await _contactService.AddContactAsync(userID, request.Address, request.City);

            if (result == null)
            {
                return(BadRequest());
            }
            return(Ok(result));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Post([FromBody] Contact contact)
        {
            try
            {
                await _ContactService.AddContactAsync(contact);

                return(Ok(Json(contact)));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> AddContact(string id)
        {
            try
            {
                await _contactService.AddContactAsync(id, UserEmail);

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error while adding contact. id: {id}");
                return(InternalServerErrorJson(ex));
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <ContactModel> > SaveContact(ContactModel contactModel)
        {
            try
            {
                var contact      = _mapper.Map <Contact>(contactModel);
                var savedContact = await _contactService.AddContactAsync(contact);

                return(_mapper.Map <ContactModel>(savedContact));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> CreateContact(
            [FromBody] ContactRequest request)
        {
            var contact = new Contact
            {
                Title           = request.Title,
                FirstName       = request.FirstName,
                LastName        = request.LastName,
                Email           = request.Email,
                MobileNumber    = request.MobileNumber,
                DateTimeCreated = DateTime.Now
            };

            var result = await _contactService.AddContactAsync(contact);

            return(Ok(result));
        }
        public async Task <IActionResult> PostAsync([FromBody] AddContact newContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var contact = _mapper.Map <AddContact, ContactInfo>(newContact);
            var result  = await _contactService.AddContactAsync(contact);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var contactResource = _mapper.Map <ContactInfo, ContactResource>(result.ContactInfo);

            return(Ok(contactResource));
        }
Ejemplo n.º 11
0
        public async Task AddContactAsync_WithContactDto_CallsRepoAddContactAsync()
        {
            var contactDto = new ContactDto
            {
                FirstName     = "Test First Name",
                MiddleName    = "Test Middle Name",
                LastName      = "Test Last Name",
                DisplayName   = "Test Display Name",
                StreetAddress = "Test Street Address",
                City          = "Test City",
                Region        = "TR",
                PostalCode    = "12345",
                Country       = "Test Country",
                PhoneNumber   = "(012) 345-6789",
                EmailAddress  = "*****@*****.**"
            };

            await _contactService.AddContactAsync(contactDto);

            _contactRepositoryMock.Verify(repo => repo.AddContactAsync(contactDto), Times.Once);
        }