Ejemplo n.º 1
0
        public ActionResult InsertNewContact(ContactModel request)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(new ServiceResponseModel {
                    Success = false, Message = "Invalid request."
                }));
            }

            _contactsService.Add(new Contacts
            {
                PhoneId      = request.PhoneId,
                FirstName    = request.FirstName,
                MiddleName   = request.MiddleName,
                LastName     = request.LastName,
                Organization = request.Organization,
                Title        = request.Title,
                MobilePhone  = request.MobilePhone,
                HomePhone    = request.HomePhone,
                Notes        = request.Notes,
                HomeAddress  = request.HomeAddress,
                NickName     = request.NickName,
                WebSite      = request.WebSite,
                BirthDay     = request.BirthDay,
                Status       = true,
                CreatedDate  = DateTime.Now,
                ModifiedDate = DateTime.Now
            });

            return(Ok(new ServiceResponseModel {
                Success = true, Message = "Request successfully"
            }));
        }
Ejemplo n.º 2
0
        private async Task AddMessage(string fromNumber, string toNumber, string text, string messageSid, string direction, Address address = null)
        {
            var contact = await _contactsService.GetByPhoneNumber(toNumber);

            if (contact == null)
            {
                contact = new Contact
                {
                    Info = new ContactInfo
                    {
                        Number = toNumber
                    }
                };

                await _contactsService.Add(contact);
            }

            if (address != null)
            {
                await _contactsService.UpdateAddress(contact.Id, address);
            }

            await _contactsService.AddMessage(contact.Id, new Message
            {
                From      = fromNumber,
                To        = toNumber,
                Text      = text,
                CreatedOn = DateTime.UtcNow,
                Direction = direction,
                Sid       = messageSid
            });
        }
Ejemplo n.º 3
0
        // POST api/<controller>
        public async Task <IHttpActionResult> Post(ContactDto contactDto)
        {
            var errorMessage = await _contactValidator.ValidateContact(contactDto);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(BadRequest(errorMessage));
            }
            return(Ok(await _contactsService.Add(contactDto)));
        }
Ejemplo n.º 4
0
 public JsonResult Post(ContactModel model)
 {
     try
     {
         return(Json(_contactsService.Add(model)));
     }
     catch (Exception ex)
     {
         return(Json(ex.Message));
     }
 }