Exemplo n.º 1
0
        public string Update(string Name, string Company, string Flag, string ID)
        {
            TouPiaoContext tc             = new TouPiaoContext();
            Guid           UID            = Guid.Parse(ID);
            string         feebackMessage = string.Empty;

            switch (Flag)
            {
            case "DU":
                User du = tc.Users.Find(UID);
                tc.Users.Remove(du);
                tc.SaveChanges();
                feebackMessage = "DELTE USER ID:" + ID;
                break;

            case "AU":
                User au = tc.Users.Find(UID);
                au.Company = Company;
                au.Name    = Name;
                tc.SaveChanges();
                feebackMessage = "UPDATE USER ID:" + ID + " COMPANY TO :" + Company + " NAME TO:" + Name;
                break;

            case "DT":
                TouPiao dt = tc.TouPiaos.Find(UID);
                tc.TouPiaos.Remove(dt);
                tc.SaveChanges();
                feebackMessage = "DELTE TOUPIAO ID:" + ID;
                break;

            default:
                break;
            }
            return(feebackMessage);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            ViewBag.FeebackMessage = string.Empty;

            Dictionary <string, object> dataList = new Dictionary <string, object>();

            TouPiaoContext tc          = new TouPiaoContext();
            string         userName    = Request["UserName"];
            string         companyName = Request["CompanyName"];
            string         checkID     = Request["checkID"];
            string         remoteAddr  = Request["REMOTE_ADDR"];
            string         remoteHost  = Request["REMOTE_HOST"];

            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(companyName) && !string.IsNullOrEmpty(checkID))
            {
                User submitUser = tc.Users.Where(u => u.Name == userName && u.Company == companyName).FirstOrDefault();

                if (submitUser != null)
                {
                    int submitCount = tc.TouPiaos.Where(t => t.User.ID == submitUser.ID).Count();
                    if (submitCount != 0)
                    {
                        SystemName targetName = tc.TouPiaos.Where(t => t.User.ID == submitUser.ID).Select(t => t.SystemName).FirstOrDefault();
                        ViewBag.FeebackMessage = "本次投票失败,您之前已投票给【" + targetName.NameCN + "/" + targetName.NameEN + "】如有疑问,请联系管理员。";
                    }
                    else
                    {
                        Guid guid = Guid.Parse(checkID);

                        TouPiao tempTouPiao = new TouPiao();
                        tempTouPiao.User       = submitUser;
                        tempTouPiao.SystemName = tc.SystemNames.Where(s => s.ID == guid).First();
                        tempTouPiao.SubmitIP   = remoteAddr;
                        tempTouPiao.SubmitMAC  = remoteHost;
                        tempTouPiao.SubmitTime = DateTime.Now;
                        tc.TouPiaos.Add(tempTouPiao);
                        tc.SaveChanges();

                        ViewBag.FeebackMessage = "投票成功";
                    }
                }
                else
                {
                    ViewBag.FeebackMessage = "投票名单不存在:" + userName + " 联系管理员处理。";
                }
            }

            dataList["NameList"] = tc.Users.OrderByDescending(k => k.Name).Select(u => u.Name).Distinct().ToList();
            ((List <string>)dataList["NameList"]).Sort();
            dataList["CompanyList"] = tc.Users.OrderByDescending(u => u.Company).Select(u => u.Company).Distinct().ToList();
            ((List <string>)dataList["CompanyList"]).Sort();
            dataList["SystemName"] = tc.SystemNames.OrderBy(u => u.SubmitTime).ToList();

            return(View(dataList));
        }