Beispiel #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (Roles.GetRolesForUser().Contains("Admin"))
            {
                string[] rolesToHide = { "Admin", "SuperAdmin" };
                ViewData["UserRoles"] = Registration.GetRoleList(rolesToHide);
            }
            else
            {
                ViewData["UserRoles"] = Registration.GetRoleList(null);
                ViewData["Clients"]   = ClientModels.GetClientNameList();
            }

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    if (Session["ClientId"] != null)
                    {
                        model.ClientId = (int)Session["ClientId"];
                    }
                    //  FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    Registration.AssignRoleToUser(model);
                    ApplicationMessages msg = new ApplicationMessages("New Employee saved successfully.", MessageType.Success);
                    ViewData["Message"] = msg;
                    return(View());
                    //return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Register()
        {
            //string userId = Membership.GetUser().ProviderUserKey.ToString();
            //string usrName = Membership.GetUser().UserName.ToString();
            //MembershipUser usr = Membership.GetUser();
            //string[] roleNames = Roles.GetRolesForUser(usrName);
            //bool x = HttpContext.User.IsInRole("SuperAdmin");

            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            if (Roles.GetRolesForUser().Contains("Admin"))
            {
                string[] rolesToHide = { "Admin", "SuperAdmin" };
                ViewData["UserRoles"] = Registration.GetRoleList(rolesToHide);
            }
            else
            {
                ViewData["UserRoles"] = Registration.GetRoleList(null);
                ViewData["Clients"]   = ClientModels.GetClientNameList();
            }

            return(View());
        }
Beispiel #3
0
        public ActionResult Close(int id, FormCollection collection, Branches br, HttpPostedFileBase agentPhoto)
        {
            ViewData["BranchTypes"] = Utilities.GetBranchTypeList();
            ViewData["States"]      = Utilities.GetStateList(Utilities.IndiaCountryCode);
            ViewData["Countries"]   = Utilities.GetCountryList();
            if (Roles.IsUserInRole("SuperAdmin"))
            {
                ViewData["Clients"] = ClientModels.GetClientNameList();
            }
            if (Session["ClientId"] != null)
            {
                br.ClientId       = (int)Session["ClientId"];
                ViewData["Zones"] = Utilities.GetZoneNameList((int)Session["ClientId"]);
                if (Session["ZoneId"] != null)
                {
                    ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], (int)Session["ZoneId"]);
                }
                else
                {
                    ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], null);
                }

                List <vw_Branches> brList = new List <vw_Branches>();
                brList = BranchModels.GetBranchesList((int)Session["ClientId"]);
                if (brList.Any(bl => bl.Id == id))
                {
                    ViewData.Model = BranchModels.GetBranchById((int)id);
                }
            }

            if (!ModelState.IsValid)
            {
                //ModelState.AddModelError("error", "Employee Id already exists");
                ApplicationMessages msg = new ApplicationMessages("Invalid entry.", MessageType.Error);
                ViewData["Message"] = msg;
                return(View());
            }

            //if (agentPhoto != null)
            //{
            //    if (agentPhoto.ContentLength > 0)
            //    {
            //        Int32 length = agentPhoto.ContentLength;
            //        byte[] tempImage = new byte[length];
            //        agentPhoto.InputStream.Read(tempImage, 0, length);
            //        br.Logo = tempImage;// file.InputStream;
            //        br.ContentType = agentPhoto.ContentType;
            //    }
            //}
            int result = BranchModels.CloseBranch(br);

            if (result > 0)
            {
                ApplicationMessages msg = new ApplicationMessages("Branch closed successfully.", MessageType.Success);
                ViewData["Message"] = msg;
            }
            else if (result == -1)
            {
                ApplicationMessages msg = new ApplicationMessages("Failed to close Branch. Please try again.", MessageType.Error);
                ViewData["Message"] = msg;
            }
            else
            {
                ApplicationMessages msg = new ApplicationMessages("Failed to close Branch. Please try again.", MessageType.Faild);
                ViewData["Message"] = msg;
            }


            return(View());
        }
Beispiel #4
0
        public ActionResult NewBranch(FormCollection collection, Branches br, HttpPostedFileBase agentPhoto)
        {
            ViewData["BranchTypes"] = Utilities.GetBranchTypeList();
            ViewData["States"]      = Utilities.GetStateList(Utilities.IndiaCountryCode);
            ViewData["Countries"]   = Utilities.GetCountryList();

            if (Roles.IsUserInRole("SuperAdmin"))
            {
                ViewData["Clients"] = ClientModels.GetClientNameList();
            }
            if (Session["ClientId"] != null)
            {
                vw_ClientList clientDetails = ClientModels.GetClientDetailsById((int)Session["ClientId"]);
                int           branchCount   = BranchModels.GetBranchesList((int)Session["ClientId"]).Count();
                if (branchCount >= clientDetails.NoOfSchoolsPermitted)
                {
                    ApplicationMessages msg = new ApplicationMessages("Your have reached to branch count max limit. Please contant administrator..", MessageType.Information);
                    ViewData["Message"] = msg;
                    return(View());
                }
                br.ClientId       = (int)Session["ClientId"];
                ViewData["Zones"] = Utilities.GetZoneNameList((int)Session["ClientId"]);
                if (Session["ZoneId"] != null)
                {
                    ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], (int)Session["ZoneId"]);
                }
                else
                {
                    ViewData["Regions"] = Utilities.GetRegionNameList((int)Session["ClientId"], null);
                }
            }



            if (!ModelState.IsValid)
            {
                //ModelState.AddModelError("error", "Employee Id already exists");
                ApplicationMessages msg = new ApplicationMessages("Invalid entry.", MessageType.Error);

                ViewData["Message"] = msg;
                return(View());
            }

            if (agentPhoto != null)
            {
                if (agentPhoto.ContentLength > 0)
                {
                    Int32  length    = agentPhoto.ContentLength;
                    byte[] tempImage = new byte[length];
                    agentPhoto.InputStream.Read(tempImage, 0, length);
                    br.Logo        = tempImage;// file.InputStream;
                    br.ContentType = agentPhoto.ContentType;
                }
            }
            int result = BranchModels.AddBranch(br);

            if (result > 0)
            {
                ApplicationMessages msg = new ApplicationMessages("New Branch saved successfully.", MessageType.Success);
                ViewData["Message"] = msg;
            }
            else if (result == -1)
            {
                ApplicationMessages msg = new ApplicationMessages("Duplicate Branch Code. Please try with new Branch Code.", MessageType.Error);
                ViewData["Message"] = msg;
            }
            else
            {
                ApplicationMessages msg = new ApplicationMessages("Failed to create a new Branch. Please try again.", MessageType.Faild);
                ViewData["Message"] = msg;
            }

            return(View());
        }