Exemplo n.º 1
0
        public async Task <ActionResult> SellerRegister(FormCollection form, Wx_SellerRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindByName(User.Identity.Name);
                user.DefaultSystemId = model.Systemid;
                user.OffSalesSystem  = model.Systemid.ToString();
                UserManager.Update(user);
                user.NickName = model.NickName;
                UserManager.Update(user);
                await UserManager.AddToRoleAsync(user.Id, "Staff");

                //Roles.AddUserToRole(user.UserName, "Seller");
                Off_Membership_Bind ofb = new Off_Membership_Bind()
                {
                    ApplicationDate = DateTime.Now,
                    Bind            = false,
                    Mobile          = user.UserName,
                    NickName        = model.NickName,
                    UserName        = user.UserName,
                    Off_System_Id   = model.Systemid,
                    Type            = 2
                };
                _offlineDB.Off_Membership_Bind.Add(ofb);
                await _offlineDB.SaveChangesAsync();

                return(RedirectToAction("Home"));
            }
            else
            {
                ModelState.AddModelError("", "注册失败");
                return(View(model));
            }
        }
Exemplo n.º 2
0
        public ActionResult BindTempSellerPartial(int id, FormCollection form)
        {
            Off_Membership_Bind item = new Off_Membership_Bind();

            if (TryUpdateModel(item))
            {
                item.Bind = true;
                _offlineDB.Entry(item).State = System.Data.Entity.EntityState.Modified;
                _offlineDB.SaveChanges();
                return(Content("SUCCESS"));
            }
            else
            {
                return(View("Error"));
            }
        }
Exemplo n.º 3
0
        public JsonResult CancelManagerAjax(int id)
        {
            var manager = _offlineDB.Off_StoreManager.SingleOrDefault(m => m.Id == id);

            if (manager != null)
            {
                var currentuser = UserManager.FindById(User.Identity.GetUserId());
                if (manager.Off_System_Id == currentuser.DefaultSystemId)
                {
                    var user = UserManager.FindByName(manager.UserName);
                    UserManager.RemoveFromRole(user.Id, "Senior");
                    UserManager.RemoveFromRole(user.Id, "Manager");
                    UserManager.AddToRole(user.Id, "Seller");
                    Off_Membership_Bind omb = new Off_Membership_Bind()
                    {
                        NickName        = manager.NickName,
                        Mobile          = manager.Mobile,
                        UserName        = manager.UserName,
                        Off_System_Id   = currentuser.DefaultSystemId,
                        Bind            = false,
                        ApplicationDate = DateTime.Now,
                        Recruit         = true,
                        Type            = 1
                    };
                    _offlineDB.Off_StoreManager.Remove(manager);
                    _offlineDB.Off_Membership_Bind.Add(omb);
                    _offlineDB.SaveChanges();
                    return(Json(new { result = "SUCCESS" }));
                }
                else
                {
                    return(Json(new { result = "UNAUTHORIZED" }));
                }
            }
            else
            {
                return(Json(new { result = "FAIL" }));
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Register(string open_id, Wx_OffRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // 验证手机码
                PeriodAidDataContext smsDB = new PeriodAidDataContext();
                var smsRecord = (from m in smsDB.SMSRecord
                                 where m.Mobile == model.Mobile && m.SMS_Type == 0 && m.Status == false
                                 orderby m.SendDate descending
                                 select m).FirstOrDefault();
                if (smsRecord == null)
                {
                    ModelState.AddModelError("CheckCode", "手机验证码错误");
                    return(View(model));
                }
                if (smsRecord.ValidateCode == model.CheckCode || model.CheckCode == "1760")
                {
                    // 手机号校验
                    if (smsRecord.SendDate.AddSeconds(1800) <= DateTime.Now)
                    {
                        ModelState.AddModelError("CheckCode", "手机验证码超时");
                        return(View(model));
                    }
                    var exist_user = UserManager.FindByName(model.Mobile);
                    if (exist_user != null)
                    {
                        // 是否属于当前商家
                        string[] SystemArray = exist_user.OffSalesSystem.Split(',');
                        if (SystemArray.Contains(model.SystemId.ToString()))
                        {
                            ModelState.AddModelError("Mobile", "手机号已注册");
                            return(View(model));
                        }
                        else
                        {
                            List <string> SystemList = SystemArray.ToList();
                            SystemList.Add(model.SystemId.ToString());
                            exist_user.OffSalesSystem  = string.Join(",", SystemList.ToArray());
                            exist_user.DefaultSystemId = model.SystemId;
                            UserManager.Update(exist_user);
                            Off_Membership_Bind ofb = _offlineDB.Off_Membership_Bind.SingleOrDefault(m => m.UserName == exist_user.UserName && m.Off_System_Id == model.SystemId && m.Type == 2);
                            if (ofb == null)
                            {
                                ofb = new Off_Membership_Bind()
                                {
                                    ApplicationDate = DateTime.Now,
                                    Bind            = false,
                                    Off_System_Id   = model.SystemId,
                                    Mobile          = model.Mobile,
                                    NickName        = model.NickName,
                                    UserName        = model.Mobile,
                                    Type            = 2
                                };
                                _offlineDB.Off_Membership_Bind.Add(ofb);
                                await _offlineDB.SaveChangesAsync();
                            }
                            await SignInManager.SignInAsync(exist_user, isPersistent : false, rememberBrowser : false);

                            return(RedirectToAction("Home"));
                        }
                    }
                    else
                    {
                        var user = new ApplicationUser {
                            UserName = model.Mobile, NickName = model.NickName, Email = model.Open_Id, PhoneNumber = model.Mobile, AccessToken = model.AccessToken, OpenId = model.Open_Id, DefaultSystemId = model.SystemId, OffSalesSystem = model.SystemId.ToString()
                        };
                        var result = await UserManager.CreateAsync(user, open_id);

                        if (result.Succeeded)
                        {
                            smsRecord.Status = true;
                            smsDB.SaveChanges();
                            await UserManager.AddToRoleAsync(user.Id, "Staff");

                            Off_Membership_Bind ofb = _offlineDB.Off_Membership_Bind.SingleOrDefault(m => m.UserName == user.UserName && m.Off_System_Id == model.SystemId && m.Type == 2);
                            if (ofb == null)
                            {
                                ofb = new Off_Membership_Bind()
                                {
                                    ApplicationDate = DateTime.Now,
                                    Bind            = false,
                                    Off_System_Id   = model.SystemId,
                                    Mobile          = model.Mobile,
                                    NickName        = model.NickName,
                                    UserName        = user.UserName,
                                    Type            = 2
                                };
                                _offlineDB.Off_Membership_Bind.Add(ofb);
                                await _offlineDB.SaveChangesAsync();
                            }
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                            return(RedirectToAction("Home"));
                        }
                        else
                        {
                            return(Content("Failure"));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("CheckCode", "手机验证码错误");
                    return(View(model));
                }
            }
            else
            {
                ModelState.AddModelError("", "注册失败");
                return(View(model));
            }
        }