示例#1
0
        private static void PatchContact(ContactItem contact, ContactItem contactData)
        {
            if (contact.Sponsor == null)
            {
                contact.Sponsor = contactData.Sponsor ?? contact.Sponsor;
            }

            contact.Email     = contact.Email ?? MailAddressItem.None;
            contact.NickName  = contactData.NickName ?? contact.NickName;
            contact.FirstName = contactData.FirstName ?? contact.FirstName;
            contact.LastName  = contactData.LastName ?? contact.LastName;
            contact.Gender    = contactData.Gender != PersonGender.Unknown ? contactData.Gender : contact.Gender;
            contact.Birthday  = contactData.Birthday ?? contact.Birthday;
            contact.Phones    = contact.Phones ?? PhoneGroupItem.Empty;
            contact.Comment   = contactData.Comment ?? contact.Comment;

            if (contactData.Email != null)
            {
                contact.Email = MailAddressItem.Create(
                    address: contactData.Email.Address ?? contact.Email.Address,
                    name: contactData.Email.Name ?? contact.Email.Name);
            }

            if (contactData.Phones != null)
            {
                contact.Phones = PhoneGroupItem.Create(
                    personal: contactData.Phones.Personal ?? contact.Phones.Personal,
                    business: contactData.Phones.Business ?? contact.Phones.Business,
                    mobile: contactData.Phones.Mobile ?? contact.Phones.Mobile,
                    other: contactData.Phones.Other ?? contact.Phones.Other);
            }
        }
示例#2
0
        public async Task <IHttpActionResult> PostAsync([FromBody] ProjectItemDto model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            var user = await _userManager.FindByEmailAsync(User.Identity.Name, cancellationToken);

            if (user == null)
            {
                return(NotFound());
            }
            if (model.Sender == null || model.Sender.Address == null)
            {
                model.Sender = MailAddressItem.Create(ApiSecurity.CurrentUserName);
            }

            var project = new ProjectItem {
                Name = model.Name, Sender = model.Sender
            };
            var validationResult = await _projectManager.CreateAsync(project, new[] { user }, cancellationToken);

            if (!validationResult.Succeeded)
            {
                return(this.ValidationContent(validationResult));
            }

            var contact = new ContactItem {
                Email = model.Sender
            };
            var businessTag = new BusinessTagItem {
                Name = "Feliratkozott", Color = "#00ff00"
            };
            await _projectManager.AddContactAsync(project, contact, cancellationToken);

            await _projectManager.AddBusinessTagAsync(project, businessTag, cancellationToken);

            await _projectManager.SetBusinessTagsAsync(new[] { contact.Id }, new[] { businessTag.Id }, new int[0], cancellationToken);

            return(CreatedAtRoute("Projects.GetById", new RouteValueDictionary {
                { "id", project.Id }
            }, new ProjectResultDto
            {
                Id = project.Id,
                Name = project.Name,
                Sender = project.Sender
            }));
        }
示例#3
0
        public async Task <ActionResult> OAuthLoginConfirmation(SignupBindingModel model, string returnUrl, CancellationToken cancellationToken)
        {
            ModelState.Remove("Password");
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExtraData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }
            if (ModelState.IsValid)
            {
                var user = await _manager.FindByEmailAsync(model.Email, cancellationToken);

                if (user == null)
                {
                    await _manager.CreateAsync(new UserItem
                    {
                        Email         = MailAddressItem.Create(model.Email, model.FirstName == null ? model.LastName : model.LastName == null ? model.FirstName : string.Join(" ", model.LastName, model.FirstName)),
                        LastName      = model.LastName,
                        FirstName     = model.FirstName,
                        Gender        = model.Gender,
                        Birthday      = model.Birthday,
                        LastIPAddress = Request.UserHostAddress,
                        LastLoginDate = DateTime.UtcNow
                    }, cancellationToken);

                    OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.Email);
                    OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("UserName", IdentityAppResources.MembershipCreateStatus_DuplicateUserName);
                }
            }
            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
        private void SetContactProperty(ContactItem contact, string property, object value)
        {
            if (value != null)
            {
                string val = value.ToString();

                if (!string.IsNullOrEmpty(val))
                {
                    switch (property)
                    {
                    case "Email":
                        contact.Email = MailAddressItem.Create(val, contact.Email.Name);
                        break;

                    case "Name":
                        contact.Email = MailAddressItem.Create(contact.Email.Address, val);
                        break;

                    case "FirstName":
                        contact.FirstName = val;
                        break;

                    case "LastName":
                        contact.LastName = val;
                        break;

                    case "Gender":
                        contact.Gender = (PersonGender)Enum.Parse(typeof(PersonGender), val);
                        break;

                    case "Birthday":
                        contact.Birthday = Convert.ToDateTime(val);
                        break;
                    }
                }
            }
        }
 private MailAddressItem GetMailAddress(int address, int name)
 {
     return(MailAddressItem.Create(GetStringOrNull(address), GetStringOrNull(name)));
 }
 /// <summary>
 /// Converts this model to a <see cref="MailAddressItem" /> type.
 /// </summary>
 /// <returns>
 /// The mail address.
 /// </returns>
 public MailAddressItem ToMailAddress()
 {
     return(MailAddressItem.Create(Address ?? Email, Name));
 }