Esempio n. 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);
            }
        }
Esempio n. 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
            }));
        }
        /// <summary>
        /// Composes a new mail message from DB data.
        /// </summary>
        /// <param name="mail">The DB message to convert to a mail message.</param>
        /// <returns>
        /// The mail message.
        /// </returns>
        protected virtual MailMessage ComposeMessage(MailAddressItem to, CommandItem command, string returnUrl)
        {
            var routeLink    = string.Join("/", RouteLink, command.Uri);
            var commitLink   = UriUtility.MakeUri(routeLink, UriKind.Absolute, new UriParameter("returnurl", returnUrl));
            var rollbackLink = UriUtility.MakeUri(routeLink, UriKind.Absolute, new UriParameter("rollback", "true"), new UriParameter("returnurl", returnUrl));
            var message      = new MailMessage
            {
                SubjectEncoding = Encoding.UTF8,
                Subject         = command.Line,
                BodyEncoding    = Encoding.UTF8,
                Body            = string.Format(HtmlBody, commitLink, rollbackLink),
                IsBodyHtml      = true
            };

            message.To.Add(new MailAddress(to.Address, to.Name, Encoding.UTF8));
            return(message);
        }
Esempio n. 4
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));
        }
        /// <summary>
        /// Sends a command in email to the given recipient asynchronously.
        /// </summary>
        /// <param name="to">The recipient.</param>
        /// <param name="command">The command to send.</param>
        /// <param name="returnUrl">Return URL.</param>
        /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <returns>
        /// The task object representing the number of the recipients.
        /// </returns>
        public virtual async Task SendAsync(MailAddressItem to, CommandItem command, string returnUrl, CancellationToken cancellationToken)
        {
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            var message = ComposeMessage(to, command, returnUrl);

            if (message == null)
            {
                throw new InvalidOperationException("The command object cannot be null.");
            }
            using (var smtpClient = new SmtpClient())
            {
                await smtpClient.SendMailAsync(message);
            }
        }
        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));
 }