Example #1
0
 public static LoginInfo Auth(string userid, string userpwd)
 {
     DbEntities db = new DbEntities();
     LoginInfo loginInfo = new LoginInfo();
     //首先判断是否为管理员
     Admin admin = db.Admin.Where(c => c.AdminId == userid).FirstOrDefault();
     if (admin != null && (CommonHelper.MD5(userpwd) == admin.AdminPwd))
     {
         loginInfo.IsSuccess = true;
         loginInfo.Message = "";
         loginInfo.LoginUserId = admin.AdminId;
         loginInfo.UserType = "管理员";
         loginInfo.UserInstance = admin;
     }
     else
     {
         Member member = db.Member.Where(c => c.MemberId == userid).FirstOrDefault();
         if (member != null && (CommonHelper.MD5(userpwd) == member.MemberPwd))
         {
             loginInfo.IsSuccess = true;
             loginInfo.Message = "";
             loginInfo.LoginUserId = member.MemberId;
             loginInfo.UserType = "会员";
             loginInfo.UserInstance = member;
         }
         else
         {
             loginInfo.IsSuccess = false;
             loginInfo.Message = "";
             loginInfo.LoginUserId = "";
             loginInfo.UserType = "";
             loginInfo.UserInstance = null;
         }
     }
     return loginInfo;
 }
Example #2
0
        public ActionResult Edit(Publication rec)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file = Request.Files["file"];
                DbEntities tempdb = new DbEntities();
                Publication ori = tempdb.Publication.Find(rec.Id);
                if (file != null && file.FileName != "")
                {
                    if (ori.FileUrl != null)
                    {
                        string oriFilePath = Path.Combine(HttpContext.Server.MapPath("/Uploads"), Path.GetFileName(ori.FileUrl));
                        if (System.IO.File.Exists(oriFilePath))
                        {
                            System.IO.File.Delete(oriFilePath);
                        }
                    }
                    string ext = Path.GetExtension(file.FileName);
                    string filename = Guid.NewGuid().ToString() + ext;
                    string filePath = Path.Combine(HttpContext.Server.MapPath("/Uploads"), filename);
                    file.SaveAs(filePath);
                    rec.FileUrl = "/Uploads/" + filename;
                }
                else
                {
                    rec.FileUrl = ori.FileUrl;
                }

                HttpPostedFileBase imagefile = Request.Files["imagefile"];
                if (imagefile != null && imagefile.FileName != "")
                {
                    if (ori.ImageUrl != null)
                    {
                        string oriImageFilePath = Path.Combine(HttpContext.Server.MapPath("/Uploads"), Path.GetFileName(ori.ImageUrl));
                        if (System.IO.File.Exists(oriImageFilePath))
                        {
                            System.IO.File.Delete(oriImageFilePath);
                        }
                    }
                    string ext = Path.GetExtension(imagefile.FileName);
                    string filename = Guid.NewGuid().ToString() + ext;
                    string filePath = Path.Combine(HttpContext.Server.MapPath("/Uploads"), filename);
                    imagefile.SaveAs(filePath);
                    rec.ImageUrl = "/Uploads/" + filename;
                }
                else
                {
                    rec.ImageUrl = ori.ImageUrl;
                }

                db.Entry(rec).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Publication", "Admin");
            }
            return View(rec);
        }