示例#1
0
        public async Task <APIResponse <Contact> > UpdateContact(string Id, ContactInput input)
        {
            Contact contact = await _contactRepo.GetByIdAsync(Id);

            if (contact == null)
            {
                return new APIResponse <Contact>()
                       {
                           Code = "400", Data = contact, Message = "Not Found!", OK = false
                       }
            }
            ;

            contact.Name        = input.Name;
            contact.MobilePhone = input.MobilePhone;
            contact.Phone       = input.Phone;
            contact.Email       = input.Email;
            contact.Address     = input.Address;
            contact.Updated     = DateTime.Now;
            contact             = await _contactRepo.UpdateAsync(Id, contact);

            return(new APIResponse <Contact>()
            {
                Code = "200", Data = contact, Message = "Success", OK = true
            });
        }
    }
示例#2
0
        public async Task <APIResponse <Contact> > AddContact(ContactInput input)
        {
            Contact contact = new Contact
            {
                Address     = input.Address,
                Email       = input.Email,
                Name        = input.Name,
                Phone       = input.Phone,
                MobilePhone = input.MobilePhone
            };

            Contact IsExist = await _contactRepo.GetAsync(x => x.Name == contact.Name);

            if (IsExist != null)
            {
                return new APIResponse <Contact>()
                       {
                           Code = "400", Data = null, Message = "There is already contact with the same name!", OK = false
                       }
            }
            ;

            Contact newContact = await _contactRepo.AddAsync(contact);

            return(new APIResponse <Contact>()
            {
                Code = "200", Data = newContact, Message = "Success", OK = true
            });
        }
示例#3
0
        /// <summary>
        /// Performs execution of the command
        /// </summary>
        protected override void ProcessRecord()
        {
            // Instantiate a new NebContactInput from the provided parameters
            ContactInput contactInput = new ContactInput();

            contactInput.UserGuid            = Guid;
            contactInput.Primary             = Primary.IsPresent;
            contactInput.CommunicationMethod = CommunicationMethod;

            // return it back to the pipeline
            WriteObject(contactInput);
        }
示例#4
0
        public async Task <IActionResult> Post(ContactInput model)
        {
            _logger.LogDebug($"Creating a new contact with Email \"{model.Email}\"");

            var contact = new Contact();

            model.MapToContact(contact);

            await _contactRepository.Create(contact);

            return(CreatedAtAction(nameof(GetById), "contact", new { id = contact.Id }, contact));
        }
示例#5
0
        public async Task <IActionResult> ContactingAdmin(ContactInput input)
        {
            if (ModelState.IsValid)
            {
                await this.emailSender.SendEmailAsync("", $"{input.Tbname} contacted you via the Contact us page with an e-mail {input.Tbemail}.", input.Message);

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
示例#6
0
        public async Task <IActionResult> Put(int id, ContactInput model)
        {
            _logger.LogDebug($"Updating a contact with id {id}");

            var contact = await _contactRepository.GetById(id);

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

            model.MapToContact(contact);

            await _contactRepository.Update(id, contact);

            return(Ok(contact));
        }
示例#7
0
 public APIResponse <Contact> UpdateContact(string Id, [FromBody] ContactInput input)
 {
     return(_contactService.UpdateContact(Id, input).Result);
 }
示例#8
0
 public APIResponse <Contact> Add([FromBody] ContactInput data)
 {
     return(_contactService.AddContact(data).Result);
 }