public JsonResult SaveDomain(DomainInfo Info)
        {
            RequestResultModel _model = new RequestResultModel();

            if (Info.Name == null || Info.Name.Trim().Length == 0)
            {
                _model          = new RequestResultModel();
                _model.Title    = "Warning";
                _model.Message  = "Name is empty. Please, enter domain name.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }


            if (Info.DomainID > 0)
            {
                Domain domain       = Web.Admin.Logic.Collections.Domains.GetBy(Info.DomainID);
                Domain domainExists = Web.Admin.Logic.Collections.Domains.GetByName(Info.Name);

                // The domain has been deleted.
                if (domain.DomainID <= 0)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Domain '{0}' doesn't exist. Please, refresh role list and try again.", domainExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                // The domain already esists.
                if (domainExists.DomainID > 0 && Info.DomainID != domainExists.DomainID)
                {
                    _model.Title   = "Warning";
                    _model.Message = String.Format("Domain '{0}' already exists. Please, change domain name and try again.", domainExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                domain.Name        = Info.Name;
                domain.Description = Info.Description;
                domain.Save();

                _model               = new RequestResultModel();
                _model.Message       = String.Format("Domain \"{0}\"has been updated.", domain.Name);
                _model.HideInSeconds = 4000;
                AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Domain domainExists = Web.Admin.Logic.Collections.Domains.GetByName(Info.Name);

                // The domain already esists.
                if (domainExists.DomainID > 0)
                {
                    _model.Title    = "Warning";
                    _model.Message  = String.Format("Domain '{0}' already exists. Please, change domain name and try again.", domainExists.Name);
                    _model.InfoType = RequestResultInfoType.ErrorOrDanger;

                    return(Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)
                    }, JsonRequestBehavior.AllowGet));
                }

                Domain Domain = new Domain();
                Domain.Name        = Info.Name;
                Domain.Description = Info.Description;
                Domain.Save();

                _model.Message = String.Format("New domain \"{0}\" has been created.", Domain.Name);

                return(Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult SaveDomain(DomainInfo Info)
        {
            RequestResultModel _model = new RequestResultModel();

            if (Info.Name == null || Info.Name.Trim().Length == 0)
            {
                _model = new RequestResultModel();
                _model.Title = "Warning";
                _model.Message = "Name is empty. Please, enter domain name.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                }, JsonRequestBehavior.AllowGet);
            }

            if (Info.DomainID > 0)
            {
                Domain domain = Web.Admin.Logic.Collections.Domains.GetBy(Info.DomainID);
                Domain domainExists = Web.Admin.Logic.Collections.Domains.GetByName(Info.Name);

                // The domain has been deleted.
                if (domain.DomainID <= 0)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Domain '{0}' doesn't exist. Please, refresh role list and try again.", domainExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                    }, JsonRequestBehavior.AllowGet);
                }

                // The domain already esists.
                if (domainExists.DomainID > 0 && Info.DomainID != domainExists.DomainID)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Domain '{0}' already exists. Please, change domain name and try again.", domainExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                    }, JsonRequestBehavior.AllowGet);
                }

                domain.Name = Info.Name;
                domain.Description = Info.Description;
                domain.Save();

                _model = new RequestResultModel();
                _model.Message = String.Format("Domain \"{0}\"has been updated.", domain.Name);
                _model.HideInSeconds = 4000;
                AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);

                return Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)

                }, JsonRequestBehavior.AllowGet);

            }
            else
            {
                Domain domainExists = Web.Admin.Logic.Collections.Domains.GetByName(Info.Name);

                // The domain already esists.
                if (domainExists.DomainID > 0)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Domain '{0}' already exists. Please, change domain name and try again.", domainExists.Name);
                    _model.InfoType = RequestResultInfoType.ErrorOrDanger;

                    return Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                    }, JsonRequestBehavior.AllowGet);
                }

                Domain Domain = new Domain();
                Domain.Name = Info.Name;
                Domain.Description = Info.Description;
                Domain.Save();

                _model.Message = String.Format("New domain \"{0}\" has been created.", Domain.Name);

                return Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)

                }, JsonRequestBehavior.AllowGet);
            }
        }