public ActionResult SendTestEmail(EmailAccountFormViewModel model)
        {
            EmailAccount Email = _hrUnitOfWork.Repository <EmailAccount>().Where(a => a.Id == model.Id).FirstOrDefault();

            if (Email != null)
            {
                try
                {
                    Db.Persistence.Services.EmailService.SendEmail(Email, "Subject Test", "Test Email", model.TestEmail, model.DisplayName);
                }
                catch (Exception ex)
                {
                    TempData["Error"] = ex.Message;
                    Models.Utils.LogError(ex.Message);
                    return(Json("", JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                ModelState.AddModelError("", MsgUtils.Instance.Trls("SaveFailed"));
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
        public ActionResult SaveEmailAccount(EmailAccountFormViewModel model, OptionsViewModel moreInfo)
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.MessageRepository.CheckForm(new CheckParm
                    {
                        CompanyId  = CompanyId,
                        ObjectName = "EmailAccountForm",
                        TableName  = "EmailAccounts",
                        Columns    = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        Culture    = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }

                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }

                var record = _hrUnitOfWork.Repository <EmailAccount>().FirstOrDefault(j => j.Id == model.Id);

                if (record == null) //Add
                {
                    record = new EmailAccount();

                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "EmailAccountForm",
                        Options     = moreInfo,
                        Transtype   = Model.Domain.TransType.Insert
                    });

                    record.CreatedTime = DateTime.Now;
                    record.CreatedUser = UserName;
                    _hrUnitOfWork.NotificationRepository.Add(record);
                }
                else //update
                {
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "EmailAccountForm",
                        Options     = moreInfo,
                        Transtype   = Model.Domain.TransType.Update
                    });

                    record.ModifiedTime = DateTime.Now;
                    record.ModifiedUser = UserName;
                    _hrUnitOfWork.NotificationRepository.Attach(record);
                    _hrUnitOfWork.NotificationRepository.Entry(record).State = EntityState.Modified;
                }
                var Errors = SaveChanges(Language);

                string message = "OK," + ((new JavaScriptSerializer()).Serialize(model));

                if (Errors.Count > 0)
                {
                    message = Errors.First().errors.First().message;
                }

                return(Json(message));
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }
        }