/*<ControllerActionImplementation:Render:1/>*/
        public ActionResult ExecuteRender()
        {
            if (_parentController == null)
            {
                _parentController = new MasterPage.MasterPageController(new  DSS1_RetailerDriverStockOptimisation.UI.ViewModels.MasterPage.MasterPageViewModel());
            }
            ((MasterPage.MasterPageController)_parentController).ExecuteRender();
            ActionResult _result = null;

            @model.Title = "";
            zAppDev.DotNet.Framework.Identity.Model.ApplicationUser user = zAppDev.DotNet.Framework.Identity.IdentityHelper.GetCurrentApplicationUser();
            if ((user?.HasPermission("IsStockManager") ?? false))
            {
                _result = GetRedirectInfo("StockManagerView", "Render", new  RouteValueDictionary(new {  }));
            }
            else if ((user?.IsInRole("Supplier") ?? false))
            {
                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "HomePage", DSS1_RetailerDriverStockOptimisation.Hubs.EventsHub.RaiseDebugMessage, "Supplier");
                _result = GetRedirectInfo("SupplierView", "Render", new  RouteValueDictionary(new {  }));
            }
            else
            {
                _result = GetRedirectInfo("StockManagerView", "Render", new  RouteValueDictionary(new {  }));
            }
            return(_result);
        }
        /*<ControllerActionImplementation:Create:1/>*/
        public ActionResult ExecuteCreate()
        {
            ActionResult _result = null;

            _result = this.ExecuteAuthorizeAccess();
            if (@model.password?.Trim() != @model.repeatPassword?.Trim())
            {
                throw new Exception("Passwords do not match!");
            }
            if (@model.username?.Trim() == "")
            {
                throw new Exception("No username provided!");
            }
            zAppDev.DotNet.Framework.Identity.Model.ApplicationRole adminRole = new DSS2_SynchromodalityCapacityOptimisation.DAL.Repository().GetAsQueryable <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>((r) => r.Name == "Administrator")?.FirstOrDefault();
            if ((adminRole == null))
            {
                throw new Exception("No Administrator role found in Database!");
            }
            zAppDev.DotNet.Framework.Identity.Model.ApplicationUser adminUser = new zAppDev.DotNet.Framework.Identity.Model.ApplicationUser();
            adminUser.UserName = (@model.username?.Trim() ?? "");
            adminUser?.AddRoles(adminRole);
            string possibleError = zAppDev.DotNet.Framework.Identity.IdentityHelper.CreateUser(adminUser, (@model.password?.Trim() ?? ""));

            if ((((possibleError == null || possibleError == "")) == false))
            {
                ClientCommand(ClientCommands.SHOW_MESSAGE, possibleError, MessageType.Error);
                return(null);
            }
            _result = GetRedirectInfo("SignInPage", "Load", new  RouteValueDictionary(new {  }));
            return(_result);
        }
        /*<ControllerActionImplementation:SubmitChanges:1/>*/
        public ActionResult ExecuteSubmitChanges()
        {
            ActionResult _result = null;

            zAppDev.DotNet.Framework.Identity.Model.ApplicationUser a = zAppDev.DotNet.Framework.Identity.IdentityHelper.GetCurrentApplicationUser();
            new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Save <zAppDev.DotNet.Framework.Identity.Model.ApplicationUser>(a);
            return(_result);
        }
Ejemplo n.º 4
0
        /*<ControllerActionImplementation:SignUp:1/>*/
        public ActionResult ExecuteSignUp()
        {
            ActionResult _result = null;

            if ((@model.PasswordTextBox != @model.RetypePass))
            {
                ClientCommand(ClientCommands.SHOW_MESSAGE, "Passwords do not match", MessageType.Warning);
                return(null);
            }
            zAppDev.DotNet.Framework.Identity.Model.ApplicationUser userToRegister = new zAppDev.DotNet.Framework.Identity.Model.ApplicationUser();
            System.Collections.Generic.List <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole> roleToAdd = new System.Collections.Generic.List <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>();
            if ((@model.ChoosenRole == null))
            {
                zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "SignUp", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "User did not select a Role.");
                ClientCommand(ClientCommands.SHOW_MESSAGE, "Please choose a role you wish to sign up as.", MessageType.Warning);
                return(null);
            }
            if (@model.ChoosenRole == "Supplier")
            {
                DSS5_SupplyChainFinancialsOptimisation.BO.Supplier newSupplier = new DSS5_SupplyChainFinancialsOptimisation.BO.Supplier();
                newSupplier.UserName = @model.UserName;
                newSupplier.Email    = @model.Email;
                if ((((((newSupplier?.Email ?? "") == null ? false : CSharpVerbalExpressions.VerbalExpressions.DefaultExpression.Add(CSharpVerbalExpressions.CommonRegex.Email).Test((newSupplier?.Email ?? "")))) == false)))
                {
                    ClientCommand(ClientCommands.SHOW_MESSAGE, "Please enter a valid e-mail address", MessageType.Warning);
                    return(null);
                }
                newSupplier.Company = @model.CompanyName;
                userToRegister      = newSupplier;
                roleToAdd           = new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Get <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>((a) => a.Name == "GuestSupplier").ToList();
            }
            if (@model.ChoosenRole == "Buyer")
            {
                DSS5_SupplyChainFinancialsOptimisation.BO.Buyer newBuyer = new DSS5_SupplyChainFinancialsOptimisation.BO.Buyer();
                newBuyer.UserName = @model.UserName;
                newBuyer.Email    = @model.Email;
                if ((((((newBuyer?.Email ?? "") == null ? false : CSharpVerbalExpressions.VerbalExpressions.DefaultExpression.Add(CSharpVerbalExpressions.CommonRegex.Email).Test((newBuyer?.Email ?? "")))) == false)))
                {
                    ClientCommand(ClientCommands.SHOW_MESSAGE, "Please enter a valid e-mail address", MessageType.Warning);
                    return(null);
                }
                newBuyer.Company = @model.CompanyName;
                userToRegister   = newBuyer;
                roleToAdd        = new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Get <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>((a) => a.Name == "Buyer").ToList();
            }
            if (@model.ChoosenRole == "Investor")
            {
                DSS5_SupplyChainFinancialsOptimisation.BO.Investor newInvestor = new DSS5_SupplyChainFinancialsOptimisation.BO.Investor();
                newInvestor.UserName = @model.UserName;
                newInvestor.Email    = @model.Email;
                if ((((((newInvestor?.Email ?? "") == null ? false : CSharpVerbalExpressions.VerbalExpressions.DefaultExpression.Add(CSharpVerbalExpressions.CommonRegex.Email).Test((newInvestor?.Email ?? "")))) == false)))
                {
                    ClientCommand(ClientCommands.SHOW_MESSAGE, "Please enter a valid e-mail address", MessageType.Warning);
                    return(null);
                }
                newInvestor.Company        = @model.CompanyName;
                newInvestor.InvestorStatus = "GuestInvestor";
                userToRegister             = newInvestor;
                roleToAdd = new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Get <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>((a) => a.Name == "GuestInvestor").ToList();
            }
            if ((@model.ChoosenRole == "Intermediary"))
            {
                DSS5_SupplyChainFinancialsOptimisation.BO.IntermediaryUser newIntermediaryUser = new DSS5_SupplyChainFinancialsOptimisation.BO.IntermediaryUser();
                newIntermediaryUser.UserName = @model.UserName;
                newIntermediaryUser.Email    = @model.Email;
                if ((((((newIntermediaryUser?.Email ?? "") == null ? false : CSharpVerbalExpressions.VerbalExpressions.DefaultExpression.Add(CSharpVerbalExpressions.CommonRegex.Email).Test((newIntermediaryUser?.Email ?? "")))) == false)))
                {
                    ClientCommand(ClientCommands.SHOW_MESSAGE, "Please enter a valid e-mail address", MessageType.Warning);
                    return(null);
                }
                newIntermediaryUser.Intermediary = @model.Intermediary;
                userToRegister = newIntermediaryUser;
                roleToAdd      = new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Get <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>((a) => a.Name == "Intermediary").ToList();
            }
            if ((new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Get <zAppDev.DotNet.Framework.Identity.Model.ApplicationUser>((a) => a.UserName == @model.UserName)).Count() > 0)
            {
                ClientCommand(ClientCommands.SHOW_MESSAGE, "Please choose a different Username", MessageType.Warning);
                return(null);
            }
            string error = zAppDev.DotNet.Framework.Identity.IdentityHelper.CreateUser(userToRegister, @model.PasswordTextBox);

            if ((((error == null || error == "")) == false))
            {
                ClientCommand(ClientCommands.SHOW_MESSAGE, error, MessageType.Warning);
                return(null);
            }
            string code = zAppDev.DotNet.Framework.Identity.IdentityHelper.GetUserManager().GenerateEmailConfirmationTokenAsync(userToRegister.UserName).Result;
            string link = (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ServerExternalPath"]) ?
                           System.Configuration.ConfigurationManager.AppSettings["ServerExternalPath"] : zAppDev.DotNet.Framework.Utilities.Web.GetApplicationPathUri(false)) +
                          "/EmailConfirmation/Confirm" + "?email=" + System.Web.HttpUtility.UrlEncode((userToRegister?.Email ?? "")) + "&code=" + System.Web.HttpUtility.UrlEncode(code);

            zAppDev.DotNet.Framework.Utilities.EMailMessage emailMessage = new zAppDev.DotNet.Framework.Utilities.EMailMessage();
            emailMessage.To = new List <string> {
                (userToRegister?.Email ?? "")
            }.ToList();
            emailMessage.Subject    = "Account Activation";
            emailMessage.Body       = "Please click <a href='" + link + "'>here</a> to activate your account";
            emailMessage.IsBodyHtml = true;
            zAppDev.DotNet.Framework.Utilities.Email.SendMail(emailMessage, true);
            userToRegister.Roles = roleToAdd.ToList();
            new DSS5_SupplyChainFinancialsOptimisation.DAL.Repository().Save <zAppDev.DotNet.Framework.Identity.Model.ApplicationUser>(userToRegister);
            ClientCommand(ClientCommands.SHOW_MESSAGE, "Please activate your account using the link sent to your email.", MessageType.Success, (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ServerExternalPath"]) ?
                                                                                                                                                System.Configuration.ConfigurationManager.AppSettings["ServerExternalPath"] : zAppDev.DotNet.Framework.Utilities.Web.GetApplicationPathUri(false)) +
                          "/HomePage/Render");
            return(_result);
        }