コード例 #1
0
        public ActionResult LoginPost(string LoginName, string LoginPassword)
        {
            LoginName = Encoding.UTF8.GetString(Convert.FromBase64String(LoginName));
            LoginPassword = new DESEncrypt().EncryptString(Encoding.UTF8.GetString(Convert.FromBase64String(LoginPassword)));

            using (DBEntities db = new DBEntities())
            {
                user User = (from u in db.users where u.LoginName == LoginName && u.LoginPassword == LoginPassword select u).FirstOrDefault();

                if (User == null && this.Request.IsAjaxRequest())
                {
                    return this.Content(new ReturnObject()
                    {
                        status = ReturnObject.EReturnStatus.error,
                        message = "<strong>登录名</strong> 或 <strong>登录密码</strong> 错误!"
                    }.ToString());
                }
                this.Session[SessionConfig.CurrentUser] = User;
                return this.Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.success,
                    message = "登录成功。"
                }.ToString());
            }
        }
コード例 #2
0
        public ActionResult LoginLogs(string userID)
        {
            using (var db = new DBEntities())
            {
                var user = (from u in db.users
                           where u.GUID == userID.ToLower()
                           select
                               new
                               {
                                   u.GUID,
                                   u.ShowName,
                                   u.LoginName,
                                   u.Email,
                                   u.CreateDateTime,
                                   LoginCount = u.user_loginlogs.Count
                               }).FirstOrDefault();

                var list = from l in db.user_loginlogs
                           where l.userID == userID.ToLower()
                           orderby l.LoginDateTime descending
                           select
                               new
                               {
                                   l.LoginDateTime
                               };

                ViewBag.userJson = BasicTools.Object2JavaScriptJsonString("userJson", user);
                ViewBag.listJson = BasicTools.Object2JavaScriptJsonString("listJson", new { items = list });
            }

            return View();
        }
コード例 #3
0
        public ActionResult Detail(string guid)
        {
            using (DBEntities db = new DBEntities())
            {
                var item = db.singles.FirstOrDefault(p => p.GUID == guid.ToLower());

                return this.Content(new ReturnObject()
                {
                    status = item == null ? ReturnObject.EReturnStatus.error : ReturnObject.EReturnStatus.success,
                    message = item == null ? "您要获取的数据不存在!" : "获取数据成功",
                    data = item
                }.ToString());
            }
        }
コード例 #4
0
        public ActionResult RegisterPost(string LoginName, string ShowName, string Email, string LoginPassword)
        {
            LoginName = Encoding.UTF8.GetString(Convert.FromBase64String(LoginName));
            ShowName = Encoding.UTF8.GetString(Convert.FromBase64String(ShowName));
            Email = Encoding.UTF8.GetString(Convert.FromBase64String(Email));
            LoginPassword = new DESEncrypt().EncryptString(Encoding.UTF8.GetString(Convert.FromBase64String(LoginPassword)));

            using (DBEntities db = new DBEntities())
            {
                if (db.users.Count(p => p.LoginName == LoginName) > 0)
                    return this.Content(new ReturnObject()
                    {
                        status = ReturnObject.EReturnStatus.error,
                        message = "<strong>登录名</strong> 已被注册,请换个 <strong>登录名</strong> !"
                    }.ToString());

                if (db.users.Count(p => p.Email == Email) > 0)
                    return this.Content(new ReturnObject()
                    {
                        status = ReturnObject.EReturnStatus.error,
                        message = "<strong>电子邮箱</strong> 已被注册,请换个 <strong>电子邮箱</strong> !"
                    }.ToString());

                var User = new user
                {
                    GUID = BasicTools.NewGuid(),
                    LoginName = LoginName,
                    Email = Email,
                    ShowName = ShowName,
                    LoginPassword = LoginPassword,
                    CreateDateTime = DateTime.Now
                };
                var User_Loginlog = new user_loginlog
                {
                    userID = User.GUID,
                    LoginDateTime = DateTime.Now
                };

                db.users.Add(User);
                db.user_loginlogs.Add(User_Loginlog);
                db.SaveChanges();

                this.Session[SessionConfig.CurrentUser] = User;
                return this.Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.success,
                    message = "注册成功!"
                }.ToString());
            }
        }
コード例 #5
0
        public ActionResult Delete(string guid)
        {
            using (DBEntities db = new DBEntities())
            {
                var item = db.singles.FirstOrDefault(p => p.GUID == guid.ToLower());

                db.singles.Remove(item);
                db.SaveChanges();

                return this.Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.success,
                    message = "删除数据成功!"
                }.ToString());
            }
        }
コード例 #6
0
        public ActionResult Edit(string jsonobj)
        {
            using (DBEntities db = new DBEntities())
            {
                var item = JsonConvert.DeserializeObject<single>(jsonobj);

                db.singles.Attach(item);
                db.Entry(item).State = System.Data.Entity.EntityState.Modified;

                db.SaveChanges();

                return this.Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.success,
                    message = "添加数据成功!",
                    data = item
                }.ToString());
            }
        }
コード例 #7
0
        public ActionResult Add(string jsonobj)
        {
            jsonobj = HttpUtility.UrlDecode(Encoding.UTF8.GetString(Convert.FromBase64String(jsonobj)));
            using (DBEntities db = new DBEntities())
            {
                var item = JsonConvert.DeserializeObject<single>(jsonobj);

                item.GUID = BasicTools.NewGuid();

                db.singles.Add(item);
                db.SaveChanges();

                return this.Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.success,
                    message = "添加数据成功!",
                    data = item
                }.ToString());
            }
        }
コード例 #8
0
        /// <summary>
        ///     User List
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            using (var db = new DBEntities())
            {
                var list = from u in db.users
                    select
                        new
                        {
                            u.GUID,
                            u.ShowName,
                            u.LoginName,
                            u.Email,
                            u.CreateDateTime,
                            LastLogin = u.user_loginlogs.Count >= 0 ? u.user_loginlogs.Max(p => p.LoginDateTime) : u.CreateDateTime,
                            LoginCount = u.user_loginlogs.Count
                        };

                ViewBag.listJson = BasicTools.Object2JavaScriptJsonString("listJson", new { items = list });
            }
            return View();
        }
コード例 #9
0
        public ActionResult UploadFile()
        {
            if (base.CurrentUser == null)
                return Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.error,
                    message = "请登录后重试。"
                }.ToString());
            HttpPostedFileBase file = Request.Files["Filedata"]; //获取单独文件的访问
            var fileGuid = Guid.NewGuid().ToString();//生成随机的GUID
            try
            {
                if (file != null)
                {
                    var fileGUID = BasicTools.NewGuid();
                    var uploadPath = Server.MapPath("~/Files/UserFiles") + "\\" + base.CurrentUser.GUID + "\\" + fileGUID;

                    //上传路径不存在则创建路径
                    if (!Directory.Exists(uploadPath))
                        Directory.CreateDirectory(uploadPath);

                    //已存在文件则删除
                    if (System.IO.File.Exists(uploadPath + "\\" + file.FileName))
                        System.IO.File.Delete(uploadPath + "\\" + file.FileName);

                    file.SaveAs(uploadPath + "\\" + file.FileName);

                    using (DBEntities db = new DBEntities())
                    {
                        System.IO.FileInfo fileInfo = new FileInfo(uploadPath + "\\" + file.FileName);

                        uploadfile uploadfile = new uploadfile()
                        {
                            GUID = fileGUID,
                            userID = base.CurrentUser.GUID,
                            Name = file.FileName,
                            Extension = fileInfo.Extension,
                            Length = fileInfo.Length,
                            CreateDateTime = DateTime.Now
                        };

                        db.uploadfiles.Add(uploadfile);
                        db.SaveChanges();
                    }

                    return Content(new ReturnObject()
                    {
                        status  = ReturnObject.EReturnStatus.success,
                        message = "上传成功!",
                        data    = new { userid = base.CurrentUser.GUID, guid = fileGUID, name = file.FileName }
                    }.ToString());

                }
                return Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.error,
                    message = "文件不存在,请重新上传!"
                }.ToString());
            }
            catch (Exception e)
            {
                return Content(new ReturnObject()
                {
                    status = ReturnObject.EReturnStatus.error,
                    message = e.Message
                }.ToString());
            }
        }
コード例 #10
0
        //
        // GET: /Single/
        public ActionResult Index(int PageSize = 25, int PageIndex = 1, int? SingleIntNumber_min = null, int? SingleIntNumber_max = null, int? SingleIntEnum = null,
            decimal? SingleMoney_min = null, decimal? SingleMoney_max = null, DateTime? SingleDatetime_min = null, DateTime? SingleDatetime_max = null,
            string SingleVarchar = null, bool? SingleBit = null)
        {
            using (DBEntities db = new DBEntities())
            {
                var query = from s in db.singles
                            where (SingleIntNumber_min == null || SingleIntNumber_min.Value <= s.SingleIntNumber) &&
                            (SingleIntNumber_max == null || SingleIntNumber_max.Value >= s.SingleIntNumber) &&
                            (SingleIntEnum == null || (J.DB.Enum.single.SingleIntEnum)SingleIntEnum.Value == s.SingleIntEnum) &&
                            (SingleMoney_min == null || SingleMoney_min.Value <= s.SingleMoney) &&
                            (SingleMoney_max == null || SingleMoney_max.Value >= s.SingleMoney) &&
                            (SingleDatetime_min == null || SingleDatetime_min.Value <= s.SingleDatetime) &&
                            (SingleDatetime_max == null || SingleDatetime_max.Value >= s.SingleDatetime) &&
                            (SingleVarchar == null || s.SingleVarchar.Contains(SingleVarchar)) &&
                            (SingleBit == null || SingleBit.Value == s.SingleBit)
                            orderby s.SingleDatetime descending
                            select s;

                int RecordCount = query.Count();

                if (RecordCount <= (PageIndex - 1) * PageSize)
                    PageIndex = 1;

                var data = query.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();

                if (Request.IsAjaxRequest())
                {
                    return this.Content(new ReturnObject()
                    {
                        status = data == null ? ReturnObject.EReturnStatus.error : ReturnObject.EReturnStatus.success,
                        message = data == null ? "您要获取的数据不存在!" : "获取数据成功",
                        data = new { items = data, RecordCount = RecordCount, PageSize = PageSize, PageIndex = PageIndex }
                    }.ToString());
                }
                else
                {
                    ViewBag.dataJson = BasicTools.Object2JavaScriptJsonString("dataJson", new { items = data, RecordCount = RecordCount, PageSize = PageSize, PageIndex = PageIndex });
                    return View();
                }
            }
        }