Esempio n. 1
0
        public ActionResult MemberChangeStatus(int id, int status)
        {
            if (status > 1 || id < 1)
            {
                return(HttpNotFound());
            }
            var u = db.Users.Find(id);

            u.Status = status;
            db.SaveChanges();
            return(Json(true));
        }
Esempio n. 2
0
        public JsonResult ChangePassword(string newpwd, string newpwdf)
        {
            if (newpwd != newpwdf)
            {
                return(Json("nopaswd"));
            }
            if (newpwd.Length > 16 && newpwd.Length < 6)
            {
                return(Json("nosix"));
            }
            int uid = Convert.ToInt32(User.Identity.Name);
            var u   = db.Users.Find(uid);

            u.Password = newpwd;
            db.SaveChanges();
            System.Web.Security.FormsAuthentication.SignOut();
            return(Json("ok"));
        }
Esempio n. 3
0
        public ActionResult Order([Bind(Include = "Title,Cash,UserId,Remark")] Order order)
        {
            order.OrderTime = DateTime.Now;

            var u = db.Users.AsNoTracking().FirstOrDefault(m => m.Id == order.UserId);

            if (u == null)
            {
                return(View());
            }
            order.UserName = u.UserName;
            using (var context = new SeEntities())
                using (var trans = context.Database.BeginTransaction())
                {
                    #region 第一代
                    if (u.ParentId > 0)//有上级
                    {
                        User u1 = context.Users.FirstOrDefault(m => m.Id == u.ParentId);
                        if (u1 != null)
                        {
                            BonusLog bonusLog1 = new BonusLog
                            {
                                UserName   = u.UserName,
                                UserId     = u.Id,
                                ToUserName = u1.UserName,
                                ToUserId   = u1.Id,
                                BonusTime  = DateTime.Now,
                                BonusType  = (int)BonusType.推荐奖,
                                Cash       = 900,
                                OldCash    = u1.Bonus,
                                NewCash    = u1.Bonus + 900,
                                Remark     = $"直推1代{u.UserName}->{u1.UserName}",
                            };
                            u1.Bonus = bonusLog1.NewCash;
                            context.BonusLogs.Add(bonusLog1);

                            #region 第二代
                            if (u1.ParentId > 0)
                            {
                                User u2 = context.Users.FirstOrDefault(m => m.Id == u1.ParentId);
                                if (u2 != null)
                                {
                                    BonusLog bonusLog2 = new BonusLog
                                    {
                                        UserName   = u1.UserName,
                                        UserId     = u1.Id,
                                        ToUserName = u2.UserName,
                                        ToUserId   = u2.Id,
                                        BonusTime  = DateTime.Now,
                                        BonusType  = (int)BonusType.推荐奖,
                                        Cash       = 700,
                                        OldCash    = u2.Bonus,
                                        NewCash    = u2.Bonus + 700,
                                        Remark     = $"直推2代{u.UserName}->{u1.UserName}->{u2.UserName}",
                                    };
                                    u2.Bonus = bonusLog2.NewCash;
                                    context.BonusLogs.Add(bonusLog2);

                                    #region 第三代
                                    if (u2.ParentId > 0)
                                    {
                                        User u3 = context.Users.FirstOrDefault(m => m.Id == u2.ParentId);
                                        if (u3 != null)
                                        {
                                            BonusLog bonusLog3 = new BonusLog
                                            {
                                                UserName   = u2.UserName,
                                                UserId     = u2.Id,
                                                ToUserName = u3.UserName,
                                                ToUserId   = u3.Id,
                                                BonusTime  = DateTime.Now,
                                                BonusType  = (int)BonusType.推荐奖,
                                                Cash       = 700,
                                                OldCash    = u3.Bonus,
                                                NewCash    = u3.Bonus + 700,
                                                Remark     = $"直推3代{u.UserName}->{u1.UserName}->{u2.UserName}->{u3.UserName}",
                                            };
                                            u3.Bonus = bonusLog3.NewCash;
                                            context.BonusLogs.Add(bonusLog3);
                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                    context.Orders.Add(order);
                    try
                    {
                        context.SaveChanges();
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                    }
                }
            return(RedirectToAction("OrderList"));
        }