Beispiel #1
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                user.Code         = CodeCreator.ReturnUserCode();
                user.IsDeleted    = false;
                user.CreationDate = DateTime.Now;
                user.Id           = Guid.NewGuid();
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            List <SelectListItem> Gender = new List <SelectListItem>();

            Gender.Add(new SelectListItem()
            {
                Text = "مرد", Value = "false"
            });
            Gender.Add(new SelectListItem()
            {
                Text = "زن", Value = "true"
            });
            ViewBag.Gender = new SelectList(Gender, "Value", "Text", user.Gender);

            ViewBag.RoleId = new SelectList(db.Roles, "Id", "Title", user.RoleId);
            return(View(user));
        }
        public User InsertUser(string fullname, string mobile)
        {
            User        oUser       = db.Users.FirstOrDefault(current => current.CellNum == mobile && current.IsDeleted == false);
            CodeCreator codeCreator = new CodeCreator();

            if (oUser == null)
            {
                User user = new User();
                user.Id           = Guid.NewGuid();
                user.FullName     = fullname;
                user.CellNum      = mobile;
                user.Password     = RandomCode().ToString();
                user.IsActive     = false;
                user.IsDeleted    = false;
                user.CreationDate = DateTime.Now;
                user.RoleId       = db.Roles.Where(current => current.Name.ToLower() == "customer").FirstOrDefault().Id;
                user.Code         = codeCreator.ReturnUserCode();

                db.Users.Add(user);

                sms.SendSms(mobile, user.Password);
                //LoginUser(user);

                return(user);
            }
            else
            {
                oUser.Password         = RandomCode().ToString();
                oUser.LastModifiedDate = DateTime.Now;
                oUser.FullName         = fullname;

                if (oUser.Code == null)
                {
                    oUser.Code = codeCreator.ReturnUserCode();
                }

                sms.SendSms(mobile, oUser.Password);
                //   LoginUser(oUser);
                return(oUser);
            }

            db.SaveChanges();
        }
Beispiel #3
0
        public ActionResult Register(RegisterViewModel oRegisterViewModel)
        {
            if (ModelState.IsValid)
            {
                bool isValidMobile = Regex.IsMatch(oRegisterViewModel.CellNumber, @"(^(09|9)[0123456789][0123456789]\d{7}$)|(^(09|9)[0123456789][0123456789]\d{7}$)", RegexOptions.IgnoreCase);

                if (!isValidMobile)
                {
                    ModelState.AddModelError("invalidMobile", "شماره موبایل وارد شده صحیح نمی باشد");
                }


                else
                {
                    User user = db.Users.FirstOrDefault(current =>
                                                        current.CellNum == oRegisterViewModel.CellNumber && current.IsActive && !current.IsDeleted);

                    if (user != null)
                    {
                        ModelState.AddModelError("duplicateMobil", "این شماره موبایل قبلا در وب سایت ثبت شده است. می توانید از قسمت ورود، وارد سایت شوید.");
                    }
                    else
                    {
                        Guid roleId = db.Roles.FirstOrDefault(current => current.Name.ToLower() == "customer").Id;

                        User oUser = new User();

                        oUser.Id           = Guid.NewGuid();
                        oUser.FullName     = oRegisterViewModel.FullName;
                        oUser.IsDeleted    = false;
                        oUser.IsActive     = false;
                        oUser.CellNum      = oRegisterViewModel.CellNumber;
                        oUser.Email        = oRegisterViewModel.Email;
                        oUser.Password     = RandomCode().ToString();
                        oUser.CreationDate = DateTime.Now;
                        oUser.RoleId       = roleId;
                        oUser.Code         = codeCreator.ReturnUserCode();

                        db.Users.Add(oUser);
                        db.SaveChanges();

                        return(RedirectToAction("activate", new{ id = oUser.Code }));
                    }
                }
            }
            RegisterViewModel register = new RegisterViewModel();

            register.FooterRecentBlog  = baseHelper.GetFooterRecentBlog();
            register.MenuServiceGroups = baseHelper.GetMenuServices();
            register.MenuProductGroups = baseHelper.GetMenu();

            return(View(register));
        }