Esempio n. 1
0
        public virtual IActionResult Create(EmailAccountModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var emailAccount = model.ToEntity <EmailAccount>();

                //set password manually
                emailAccount.Password = model.Password;
                _emailAccountService.InsertEmailAccount(emailAccount);

                //activity log
                _customerActivityService.InsertActivity("AddNewEmailAccount",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewEmailAccount"), emailAccount.Id), emailAccount);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Configuration.EmailAccounts.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = emailAccount.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = _emailAccountModelFactory.PrepareEmailAccountModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public virtual IActionResult Create(EmailAccountModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                EmailAccount emailAccount = model.ToEntity <EmailAccount>();

                //set password manually
                emailAccount.Password = model.Password;
                _emailAccountService.InsertEmailAccount(emailAccount);

                //activity log
                _customerActivityService.InsertActivity("AddNewEmailAccount",
                                                        string.Format("AddNewEmailAccount{0}", emailAccount.Id), emailAccount);

                SuccessNotification("Added");

                return(continueEditing ? RedirectToAction("Edit", new { id = emailAccount.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = _emailAccountModelFactory.PrepareEmailAccountModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        public JsonResult Add(EmailAccountModel model)
        {
            var email = model.ToEntity();

            _emailAccountService.InsertEmailAccount(email);
            return(Json(true));
        }
        /// <summary>
        /// Get email account identifier
        /// </summary>
        /// <param name="emailAccountService">Email account service</param>
        /// <param name="senderId">Sender identifier</param>
        /// <param name="error">Errors</param>
        /// <returns>Email account identifier</returns>
        public int GetEmailAccountId(IEmailAccountService emailAccountService, string senderId, out string error)
        {
            error = string.Empty;
            if (!IsConfigured)
            {
                return(0);
            }

            //get all available senders
            var sendersParams = new Dictionary <string, string> {
                { "option", "" }
            };
            var senders = Manager.get_senders(sendersParams);

            if (!IsSuccess(senders))
            {
                error = (string)senders.message;
                return(0);
            }

            foreach (var sender in senders.data)
            {
                if (sender.id == senderId)
                {
                    //try to find existing email account by name and email
                    var emailAccount = emailAccountService.GetAllEmailAccounts().FirstOrDefault(x =>
                                                                                                x.DisplayName == (string)sender.from_name && x.Email == (string)sender.from_email);
                    if (emailAccount != null)
                    {
                        return(emailAccount.Id);
                    }

                    //or create new one
                    var smtp = Manager.get_smtp_details();
                    if (!IsSuccess(smtp))
                    {
                        error = (string)senders.message;
                        return(0);
                    }

                    var newEmailAccount = new EmailAccount()
                    {
                        Host        = smtp.data.relay_data.data.relay,
                        Port        = smtp.data.relay_data.data.port,
                        Username    = smtp.data.relay_data.data.username,
                        Password    = smtp.data.relay_data.data.password,
                        EnableSsl   = true,
                        Email       = sender.from_email,
                        DisplayName = sender.from_name
                    };
                    emailAccountService.InsertEmailAccount(newEmailAccount);

                    return(newEmailAccount.Id);
                }
            }

            return(0);
        }
        public virtual EmailAccount InsertEmailAccountModel(EmailAccountModel model)
        {
            var emailAccount = model.ToEntity();

            //set password manually
            emailAccount.Password = model.Password;
            _emailAccountService.InsertEmailAccount(emailAccount);
            return(emailAccount);
        }
        public ActionResult Create(EmailAccountModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var emailAccount = model.ToEntity();
                _emailAccountService.InsertEmailAccount(emailAccount);

                NotifySuccess(_localizationService.GetResource("Admin.Configuration.EmailAccounts.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = emailAccount.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 7
0
        public ActionResult Create(EmailAccountModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var emailAccount = model.ToEntity();
                //set password manually
                emailAccount.Password = model.Password;
                _emailAccountService.InsertEmailAccount(emailAccount);
                return(continueEditing ? RedirectToAction("Edit", new { id = emailAccount.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 8
0
        public HttpResponseMessage CreateEmail(HttpRequestMessage request, EmailAccountVM model, bool continueEditing = false)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No items found");
                if (true)
                {
                    if (ModelState.IsValid)
                    {
                        var emailAccount = model.ToEntity();
                        //set password manually
                        emailAccount.Password = model.Password;
                        _emailAccountService.InsertEmailAccount(emailAccount);

                        //activity log
                        _customerActivityService.InsertActivity("AddNewEmailAccount", _localizationService.GetResource("ActivityLog.AddNewEmailAccount"), emailAccount.Id);

                        _baseService.Commit();
                        //SuccessNotification(_localizationService.GetResource("Admin.Configuration.EmailAccounts.Added"));

                        if (continueEditing)
                        {
                            Url.Route("GetEmailById", new { id = emailAccount.Id });
                            string nUri = Url.Link("GetEmailById", new { id = emailAccount.Id });
                            response.Headers.Location = new Uri(nUri);
                        }
                        else
                        {
                            Url.Route("EmailList", null);
                            string nuri = Url.Link("EmailList", null);
                            response.Headers.Location = new Uri(nuri);
                        }
                    }
                    else
                    {
                        //If we got this far, something failed, redisplay form
                        response = request.CreateResponse <EmailAccountVM>(HttpStatusCode.OK, model);
                    }
                }
                else
                {
                    response = AccessDeniedView(request);
                    // response = request.CreateResponse(HttpStatusCode.Unauthorized, "Unauthorized user");
                }
                return response;
            }));
        }
Esempio n. 9
0
        public ActionResult Create(EmailAccountModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var emailAccount = model.ToEntity();
                _emailAccountService.InsertEmailAccount(emailAccount);

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.EmailAccounts.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = emailAccount.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 10
0
        public virtual ActionResult Create(EmailAccountModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageEmailAccounts))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var emailAccount = model.ToEntity();
                //手动设置密码
                emailAccount.Password = model.Password;

                _emailAccountService.InsertEmailAccount(emailAccount);
                _customerActivityService.InsertActivity("AddNewEmailAccount", _localizationService.GetResource("ActivityLog.AddNewEmailAccount"), emailAccount.Id);

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.EmailAccounts.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = emailAccount.Id }) : RedirectToAction("List"));
            }

            return(View(model));
        }
Esempio n. 11
0
 /// <summary>
 /// Inserts an email account
 /// </summary>
 /// <param name="emailAccount">Email account</param>
 public void InsertEmailAccount(EmailAccount emailAccount)
 {
     _emailAccountService.InsertEmailAccount(emailAccount);
 }