예제 #1
0
        /// <summary>
        /// Creates account contact.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <param name="accountID">
        /// The account id.
        /// </param>
        /// <returns>
        /// The customer contact.
        /// </returns>
        private static async Task <ContactGetModel> CreateAccountContact(
            string accessToken,
            string accountID)
        {
            // Generate dummy data to create a new account contact.
            var name            = $"imqa-cntapi{CreateRandomString(16)}";
            var login           = $"{name}@qa.qa";
            var contactToCreate = new ContactCreateModel
            {
                Login            = login,
                Name             = name,
                Email            = login,
                AlternativeEmail = login,
                Phone            = "1234567890",
                CellularPhone    = "1234567890",
                Password         = $"{CreateRandomString(8)}!@#",

                // For the full list of available roles, see https://FAQ.intermedia.net/Article/23265
                AccessRoleNames = new[]
                {
                    "ContactManager",
                    "TechnicalAdministrator",
                    "SharePoint"
                }
            };

            // Consider https://cp.serverdata.net/webservices/restapi/docs-ui/index#!/Account_contacts/AccountContactsV1_PostContact_0
            return(await CallUsingHttpClientAsync <ContactCreateModel, ContactGetModel>(
                       $"{ResourceServerEndpointAddress}/accounts/{accountID}/contacts",
                       HttpMethod.Post,
                       accessToken,
                       contactToCreate));
        }
예제 #2
0
        public async Task <JsonResult> CreateContactAsync([FromBody] ContactCreateModel model)
        {
            Address address = new Address()
            {
                StreetAddress = model.StreetAddress,
                City          = model.City,
                State         = model.State,
                Country       = model.Country,
                ZipCode       = model.ZipCode
            };

            Contact contact = new Contact()
            {
                Name                = model.Name,
                Company             = model.Company,
                ProfileImageUrl     = model.ProfileImageUrl,
                Email               = model.Email,
                Birthdate           = Convert.ToDateTime(model.Birthdate),
                WorkPhoneNumber     = model.WorkPhoneNumber,
                PersonalPhoneNumber = model.PersonalPhoneNumber,
                Address             = address
            };
            var createdContact = await _contactRepository.AddContact(contact);

            return(new JsonResult(PopulateContactViewModel(createdContact)));
        }
예제 #3
0
        public async Task <IActionResult> Post([FromBody] ContactCreateModel model)
        {
            var contactDto = _mapper.Map <ContactCreateDto>(model);

            var contact = await _contactService.AddAsync(contactDto);

            return(CreatedAtRoute("Get", new { id = contact.Id }, contact));
        }
예제 #4
0
        public ActionResult Create(ContactCreateModel model)
        {
            var command = new CreateContactCommand()
            {
                ContactId = Guid.NewGuid(),
                Name      = model.Name
            };

            createContactHandler.Handle(command);

            return(RedirectToAction("Index"));
        }
예제 #5
0
        public IActionResult Create(ContactCreateModel contact)
        {
            if (!TryValidateModel(contact))
            {
                return(View(contact));
            }

            byte[] file;

            //if (contact.Avatar != null)
            //{
            //    file = GetBytesFromFile(contact.Avatar);
            //}
            //else
            //{
            //    file = new byte[] { };
            //}



            var contactToDb = new Contact()
            {
                FirstName   = contact.FirstName,
                LastName    = contact.LastName,
                PhoneNumber = contact.PhoneNumber,
                Addres      = contact.Address,
                Email       = contact.Email,
                Description = contact.Description,
                BirthDate   = contact.BirthDate
            };

            if (contact.Avatar != null)
            {
                var uniqueFileName = Guid.NewGuid().ToString() + Path.GetExtension(contact.Avatar.FileName);
                var path           = Path.Combine(_hostEnvironment.WebRootPath, "photos", uniqueFileName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    contact.Avatar.CopyTo(stream);
                }

                contactToDb.PhotoUrl = "/photos/" + uniqueFileName;
            }

            _contactDatabase.Insert(contactToDb);

            return(RedirectToAction("Index"));
        }
예제 #6
0
        public async Task <ActionResult <ContactModel> > PostContact(ContactCreateModel model)
        {
            var campaign = DB.ContactGroups.Find(model.ContactGroup_Id)?.Campaign;

            var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(DB.ContactGroups, Operation.Update);

            if (result.Fail())
            {
                return(result);
            }

            var entity = GetEntity(model);

            DB_TABLE.Add(entity);
            await DB.SaveChangesAsync();

            Log(DB_TABLE.GetName(), Operation.Create, campaign.Id, GetModel(entity));

            return(CreatedAtAction(nameof(GetContact), new { id = entity.Id }, GetModel(entity)));
        }