Beispiel #1
0
        public ActionResult Add(string title, int classify, string content)
        {
            List<Plate> platelist = new List<Plate>();
            platelist = (from p in db.Plates where p.IsColse == false select p).ToList();
            ViewBag.platelist = platelist;
            if (ModelState.IsValid)
            {
                try
                {
                    User user = new User();
                    db.Users.Find(CurrentUser.ID);
                    user.Integration += 20;

                    IntegrationRecord integration = new IntegrationRecord();
                    integration.Hint = "发布帖子送积分";
                    integration.Integration = 20;
                    integration.Time = DateTime.Now;
                    integration.UserID = CurrentUser.ID;
                    db.IntegrationRecords.Add(integration);
                    db.SaveChanges();

                    Topic topic = new Topic();
                    topic.Title = title;
                    topic.Content = content;
                    topic.Top = false;
                    topic.Time = DateTime.Now;
                    topic.PlateID = classify;
                    topic.UserID = CurrentUser.ID;
                    topic.Report = 0;
                    topic.Reward = 5;
                    topic.Browses = 0;
                    topic.IsOfficeIdentified = false;
                    topic.IsShow = true;
                    db.Topics.Add(topic);
                    db.SaveChanges();
                    return Redirect("/Bbs/Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "数据异常,请审核后重新提交");
                    log.Error(new LogContent("增加主题失败", Helpers.HttpHelper.GetIPAddress()), ex);
                }
            }
            else
            {
                ModelState.AddModelError("", "信息不全,请审核后提交");
            }
            ViewBag.platelist = db.Plates.Where(x => x.IsColse == false).ToList();
            return View();
        }
Beispiel #2
0
        public ActionResult Login(vLogin model, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.UserType == UserType.User)
                    {
                        User user = new User();
                        model.Password = Helpers.Encryt.GetMD5(model.Password);
                        user = db.Users.Where(u => u.UserName == model.Username && u.Password == model.Password).SingleOrDefault();
                        if (user == null)
                        {
                            ModelState.AddModelError("", "用户名或密码错误!");
                        }
                        else
                        {
                            Session["usertype"] = UserType.User;
                            FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);

                            IntegrationRecord integrationrecord = new IntegrationRecord();
                            integrationrecord = (from i in db.IntegrationRecords where i.UserID == user.ID orderby i.Time descending select i).FirstOrDefault();

                            if (integrationrecord != null)
                            {
                                if (string.Format("{0:D}", integrationrecord.Time) != string.Format("{0:D}", DateTime.Now))
                                {
                                    integrationrecord.Integration = 10;
                                    integrationrecord.Time = DateTime.Now;
                                    integrationrecord.Hint = "每日首次登陆获取积分";
                                    db.IntegrationRecords.Add(integrationrecord);
                                    user.Integration = user.Integration + 10;
                                    db.SaveChanges();
                                }
                            }
                            else
                            {
                                IntegrationRecord integrationrecord1 = new IntegrationRecord();
                                integrationrecord1.UserID = user.ID;
                                integrationrecord1.Integration = 10;
                                integrationrecord1.Time = DateTime.Now;
                                integrationrecord1.Hint = "每日首次登陆获取积分";
                                db.IntegrationRecords.Add(integrationrecord1);
                                user.Integration = user.Integration + 10;
                                db.SaveChanges();
                            }
                            log.Info(new LogContent(user.UserName + "-用户登录", Helpers.HttpHelper.GetIPAddress()));

                            if (string.IsNullOrEmpty(returnUrl))
                                return RedirectToAction("Index", "Home");
                            else
                                return Redirect(returnUrl);
                        }
                    }
                    else if (model.UserType == UserType.UserGroup)
                    {
                        UserGroup user = new UserGroup();
                        model.Password = Helpers.Encryt.GetMD5(model.Password);
                        user = db.UserGroups.Where(ug => ug.LoginName == model.Username && ug.LoginPassword == model.Password).SingleOrDefault();
                        if (user == null)
                        {
                            ModelState.AddModelError("", "用户名或密码错误!");
                        }
                        else
                        {
                            Session["usertype"] = UserType.UserGroup;
                            FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
                            if (string.IsNullOrEmpty(returnUrl))
                                return RedirectToAction("Index", "Home");
                            else
                                return Redirect(returnUrl);
                        }
                    }
                    else if (model.UserType == UserType.Business)
                    {
                        Business user = new Business();
                        model.Password = Helpers.Encryt.GetMD5(model.Password);
                        user = db.Businesses.Where(b => b.LoginName == model.Username && b.LoginPassword == model.Password).SingleOrDefault();
                        if (user == null)
                        {
                            ModelState.AddModelError("", "用户名或密码错误!");
                        }
                        else
                        {
                            Session["usertype"] = UserType.Business;
                            FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
                            if (string.IsNullOrEmpty(returnUrl))
                                return RedirectToAction("Index", "Home");
                            else
                                return Redirect(returnUrl);
                        }
                    }
                    else
                    {
                        return RedirectToAction("/Shared/AccessDenied");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "登陆信息错误请重新填写!");
                }
                ViewBag.returnUrl = returnUrl;
                return View(model);
            }
            catch (Exception ex)
            {
                log.Error(new LogContent("登录出错", HttpHelper.GetIPAddress()), ex);
                ViewBag.returnUrl = returnUrl;
                return View();
            }
        }