public ActionResult Add(Business model, HttpPostedFileBase file)
 {
     var industries = db.Industries.ToList();
     var cities = db.Cities.ToList();
     ViewBag.Industries = industries;
     ViewBag.Cities = cities;
     if (ModelState.IsValid)
     {
         if (file != null)
         {
             System.IO.Stream stream = file.InputStream;
             byte[] buffer = new byte[stream.Length];
             stream.Read(buffer, 0, (int)stream.Length);
             stream.Close();
             model.Picture = buffer;
         }
         model.LoginPassword = Helpers.Encryt.GetMD5(model.LoginPassword);
         model.AddTime = DateTime.Now;
         db.Businesses.Add(model);
         db.SaveChanges();
         return Redirect("/Admin/Business/Index");
     }
     else
     {
         ModelState.AddModelError("", "商家信息填写错误!");
     }
     return View();
 }
 public ActionResult AddBusinessPicture(Business model, HttpPostedFileBase file)
 {
     Business business = db.Businesses.Find(model.ID);
     if (business != null)
     {
         if (file != null)
         {
             try
             {
                 string random = DateHelper.GetTimeStamp();
                 Images product_img = new Images();
                 product_img.TID = model.ID;
                 product_img.ImageType = ImageType.Business;
                 product_img.ContentType = file.ContentType;
                 product_img.Time = DateTime.Now;
                 string root = "~/BusinessFile/" + business.BusinessName + "/";
                 var phicyPath = HostingEnvironment.MapPath(root);
                 Directory.CreateDirectory(phicyPath);
                 file.SaveAs(phicyPath + random + file.FileName);
                 product_img.Path = "/BusinessFile/" + business.BusinessName + "/" + random + file.FileName;
                 db.Images.Add(product_img);
                 db.SaveChanges();
                 return Redirect("/Business/BusinessPictureShow/" + business.ID);
             }
             catch (Exception ex)
             {
                 log.Error(new LogContent("商户宣传图片增加出错", HttpHelper.GetIPAddress()), ex);
                 return Redirect("/Business/AddBusinessPicture/"+model.ID);
             }
         }
         else
         {
             return Redirect("/Business/BusinessPictureShow/" + business.ID);
         }
     }
     else
     {
         return Redirect("/Shared/Info?msg=该商户不存在,请不要不合理操作");
     }
 }
Exemple #3
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();
            }
        }
 public ActionResult PictureEdit(int id)
 {
     Business business = new Business();
     business = db.Businesses.Find(id);
     if (business != null)
     {
         try
         {
             ViewBag.Business = business;
             return View();
         }
         catch (Exception ex)
         {
             log.Error(new LogContent("修改商户密码出错", HttpHelper.GetIPAddress()), ex);
             return Redirect("/Business/PictureEdit/"+id);
         }
     }
     else
     {
         return Redirect("/Shared/Info?msg=该商户不存在,请不要不合理操作");
     }
 }
 public ActionResult Edit(Business model, int id)
 {
     AjaxModel ajamodel = new AjaxModel();
     if (ModelState.IsValid)
     {
         try
         {
             Business business = db.Businesses.Find(model.ID);
             ViewBag.Business = business;
             business.BusinessName = model.BusinessName;
             business.Description = model.Description;
             business.Phone = model.Phone;
             business.Address = model.Address;
             business.WhatApp = model.WhatApp;
             business.Email = model.Email;
             business.City = model.City;
             business.Weibo = model.Weibo;
             business.Industry = model.Industry;
             db.SaveChanges();
             ajamodel.Statu = "ok";
             ajamodel.Msg = "修改成功";
         }
         catch (Exception ex)
         {
             ajamodel.Statu = "err";
             ajamodel.Msg = "修改失败,请审核一下填写的信息";
             log.Error(new LogContent("商户信息修改出错", HttpHelper.GetIPAddress()), ex);
         }
     }
     else
     {
         ajamodel.Statu = "err";
         ajamodel.Msg = "修改失败,请审核一下填写的信息";
     }
     return Json(ajamodel);
 }
 public ActionResult ShowPicture(int id)
 {
     Business business = new Business();
     business = db.Businesses.Find(id);
     if (business.Picture != null)
     {
         return File(business.Picture, "image/jpg");
     }
     else
     {
         return File("/Images/userphoto.png", "image/jpg");
     }
 }
 public ActionResult Edit(int id)
 {
     Business business = new Business();
     business = db.Businesses.Find(id);
     ViewBag.Business = business;
     return View();
 }
 /// <summary>
 /// 图标显示
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult ShowPicture(int id)
 {
     Business business = new Business();
     business = db.Businesses.Find(id);
     return File(business.Picture, "image/jpg");
 }
 public ActionResult Edit(Business model, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         var business = db.Businesses.Find(model.ID);
         if (file != null)
         {
             System.IO.Stream stream = file.InputStream;
             byte[] buffer = new byte[stream.Length];
             stream.Read(buffer, 0, (int)stream.Length);
             stream.Close();
             business.Picture = buffer;
         }
         business.BusinessName = model.BusinessName;
         business.Description = model.Description;
         business.City = model.City;
         business.Phone = model.Phone;
         business.LoginName = model.LoginName;
         business.LoginPassword = Helpers.Encryt.GetMD5(model.LoginPassword);
         business.Email = model.Email;
         business.WhatApp = model.WhatApp;
         business.Weibo = model.Weibo;
         business.Address = model.Address;
         business.Priority = model.Priority;
         db.SaveChanges();
         return Redirect("/Admin/Business/Index");
     }
     else
     {
         ModelState.AddModelError("", "商家信息填写错误!");
     }
     return View();
 }