public IActionResult Post([FromBody] ContactAreaForm model)
        {
            if (ModelState.IsValid)
            {
                var category = new ContactArea
                {
                    Name = model.Name
                };

                _contactRepository.Add(category);
                _contactRepository.SaveChanges();

                return(Ok());
            }
            return(BadRequest(ModelState));
        }
        private LocalizedContentProperty CreateOrUpdateTranslation(IQueryable <LocalizedContentProperty> localizedContentProperties, ContactArea contactArea, string propertyName, string culture)
        {
            var localizedProperty = localizedContentProperties.FirstOrDefault(x => x.ProperyName == propertyName);

            if (localizedProperty == null)
            {
                localizedProperty = new LocalizedContentProperty
                {
                    CultureId   = culture,
                    EntityId    = contactArea.Id,
                    EntityType  = contactArea.GetType().Name,
                    ProperyName = propertyName
                };

                _localizedContentPropertyRepository.Add(localizedProperty);
            }

            return(localizedProperty);
        }
Exemplo n.º 3
0
            private async Task <bool> SendEmail(ObjectId userId, ContactArea area, Message message, CancellationToken cancellationToken)
            {
                try
                {
                    var user = await GetUser(userId, cancellationToken);

                    /*var emailData = new EmailUserData {
                     *  Email = area.Email,
                     *  Name = user.Name,
                     *  ExtraData = new Dictionary<string, string> {
                     *      { "contactArea", area.Description },
                     *      { "userName", user.UserName },
                     *      { "userEmail", user.Email },
                     *      { "title", message.Title },
                     *      { "text", message.Text },
                     *      { "fileUrl", message.FileUrl }
                     *  }
                     * };
                     *
                     * var template = string.IsNullOrEmpty(message.FileUrl) ? "BTG-CostumerSupportMessage" : "BTG-CostumerSupportMessageFile";
                     *
                     * await _provider.SendEmail(
                     *  emailData,
                     *  "Academia - " + "[" + area.Description + "]" + " - " + message.Title,
                     *  template
                     * );*/

                    var templateId = string.IsNullOrEmpty(message.FileUrl) ? "775bc342-9028-43db-9afc-275c1d878bc2" : "07d4f0cf-044e-4bcb-98c8-b3502bf01ad6";

                    var client = new SendGridClient(_sendGridOptions.Value.SendGridKey);
                    var msg    = new SendGridMessage()
                    {
                        From             = new EmailAddress(_sendGridOptions.Value.Domain, "Contato"),
                        Subject          = "Academia - " + "[" + area.Description + "]" + " - " + message.Title,
                        TemplateId       = templateId,
                        Personalizations = new List <Personalization>
                        {
                            new Personalization
                            {
                                Tos = new List <EmailAddress>
                                {
                                    new EmailAddress(user.Email, user.UserName),
                                    new EmailAddress(area.Email, "Contato")
                                },
                                Substitutions = new Dictionary <string, string> {
                                    { "-contactArea-", area.Description },
                                    { "-userName-", user.UserName },
                                    { "-userEmail-", user.Email },
                                    { "-title-", message.Title },
                                    { "-text-", message.Text },
                                    { "-fileUrl-", message.FileUrl }
                                }
                            }
                        }
                    };

                    var response = await client.SendEmailAsync(msg);

                    if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
                    {
                        return(true);
                    }

                    return(false);
                }
                catch (Exception)
                {
                    return(false);
                }
            }