Example #1
0
        public ActionResult Edit(ShopJobAd jobAd)
        {
            UserModel userModel = new UserModel();
            int userId = userModel.GetUserInfo(User.Identity.Name).Id;

            JobModel jobModel = new JobModel();
            ShopJobAd shopJobAd = jobModel.GetShopJobAd(jobAd.Id);
            shopJobAd.JobTitle = jobAd.JobTitle;
            shopJobAd.ShopId = jobAd.ShopId;
            shopJobAd.LastModifyAt = DateTime.Now;
            shopJobAd.LastModifyBy = userId;
            shopJobAd.Description = jobAd.Description;
            shopJobAd.ContactPhone = jobAd.ContactPhone;
            shopJobAd.OrderIndex = jobAd.OrderIndex;
            shopJobAd.WorkPlace = jobAd.WorkPlace;
            shopJobAd.SalaryMin = jobAd.SalaryMin;
            shopJobAd.SalaryMax = jobAd.SalaryMin;
            shopJobAd.JobType = jobAd.JobType;
            jobModel.Save();

            ShopJobAdModifyLog modifyLog = new ShopJobAdModifyLog();
            modifyLog.JobId = jobAd.Id;
            modifyLog.ModifyAt = shopJobAd.LastModifyAt;
            modifyLog.ModifyBy = shopJobAd.LastModifyBy;
            jobModel.Add(modifyLog);
            return RedirectToRoute("JobListOfShopOfMine", new { mine = 1 });
        }
Example #2
0
        public ActionResult AddFavoriteShop(int shopId)
        {
            if(!User.Identity.IsAuthenticated)
                return Json(new { type = 2 }, JsonRequestBehavior.AllowGet);

            try
            {
                ShopModel shopModel = new ShopModel();
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

                if(userModel.GetUserFavoriteShop(shopId, userInfo.Id) != null)
                    return Json(new { type = 1 }, JsonRequestBehavior.AllowGet);

                UserFavoriteShop favShop = new UserFavoriteShop();
                favShop.UserId = userInfo.Id;
                favShop.ShopId = shopId;
                favShop.CreateTime = DateTime.Now;
                userModel.Add(favShop);
            }
            catch(Exception ex)
            {
                return Json(new { type = 0, data = ex.Message }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { type = 1 }, JsonRequestBehavior.AllowGet);
        }
 // 返回用户对应的角色
 public static string GetRole(string userName)
 {
     if(string.IsNullOrWhiteSpace(userName))
         return "0";
     UserModel accountModel = new UserModel();
     var userGrade = accountModel.GetUserGrade(userName);
     return userGrade.GradeLevel.ToString();
 }
Example #4
0
        public ActionResult ChangePassword(ChangePassword pwdForm)
        {
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

            userInfo.Password = userModel.PasswordEncrypt(pwdForm.NewPassword);
            userModel.Save();

            userModel.SignOut();

            return RedirectToAction("Login");
        }
Example #5
0
 public ActionResult Create(ShopJobAd jobAd)
 {
     jobAd.PublishedAt = DateTime.Now;
     UserModel userModel = new UserModel();
     jobAd.PublishedBy = userModel.GetUserInfo(User.Identity.Name).Id;
     jobAd.LastModifyBy = jobAd.PublishedBy;
     jobAd.LastModifyAt = jobAd.PublishedAt;
     jobAd.DateDue = jobAd.PublishedAt.AddMonths(1);
     JobModel jobModel = new JobModel();
     jobModel.Add(jobAd);
     return RedirectToRoute("JobListOfShopOfMine", new { mine = 1 });
 }
Example #6
0
        public ActionResult CancelFavoriteShop(int shopId)
        {
            try
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                UserFavoriteShop favShop = userModel.GetUserFavoriteShop(shopId, userInfo.Id);
                userModel.Delete(favShop);
            }
            catch(Exception ex)
            {
                return Json(new { type = 0, data = ex.Message }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { type = 1 }, JsonRequestBehavior.AllowGet);
        }
Example #7
0
 public IQueryable<V_ShopJobAd> GetShopJobAds(int? shopId, int serviceAreaId, string userName,string jobName = "")
 {
     IQueryable<V_ShopJobAd> result;
     if(shopId != null)
         result = db.V_ShopJobAd.Where(r => r.ShopId == shopId.Value);
     else
     {
         if(!String.IsNullOrWhiteSpace(userName))
         {
             UserModel userModel = new UserModel();
             V_UserInfoDetail userInfo = userModel.GetUserInfoDetail(userName);
             if(userInfo.GradeLevel >= 9)
                 result = db.V_ShopJobAd.Where(r => (r.PublishedByUserId == userInfo.Id || r.LastModifyByUserId == userInfo.Id));
             else
                 result = db.V_ShopJobAd;
         }
         else
             result = db.V_ShopJobAd;
     }
     return result.Where(r=> r.JobTitle.Contains(jobName) && r.AreaId == serviceAreaId).OrderByDescending(r => r.PublishedAt).ThenByDescending(r => r.OrderIndex);
 }
Example #8
0
        public ActionResult AddComment(FormCollection formCollection)
        {
            int shopId = int.Parse(formCollection.Get("ShopId"));
            string star = formCollection.Get("CommentStar");
            string payMoney = formCollection.Get("PayMoney");
            string deliveryTime = formCollection.Get("DeliveryTime");
            string content = formCollection.Get("CommentContent");
            string requestUrl = formCollection.Get("RequestUrl");

            UserModel userModel = new UserModel();
            ShopModel shopModel = new ShopModel();

            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

            ShopComment shopComment = new ShopComment();
            shopComment.ShopId = shopId;
            shopComment.UserId = userInfo.Id;
            shopComment.Stars = String.IsNullOrWhiteSpace(star) ? (short)0 : short.Parse(star);
            shopComment.PayMoney = String.IsNullOrWhiteSpace(payMoney) ? (short)0 : short.Parse(payMoney);
            shopComment.DeliveryTime = String.IsNullOrWhiteSpace(deliveryTime) ? (short)0 : short.Parse(deliveryTime);
            shopComment.Comment = content;
            shopComment.CreateTime = DateTime.Now;
            shopModel.Add(shopComment);

            short shopAvgStars = (short)Math.Round(shopModel.GetShopComments(shopComment.ShopId).Average(r => r.Stars));
            short shopAvgPayMoney = (short)Math.Round(shopModel.GetShopComments(shopComment.ShopId).Average(r => r.PayMoney));
            short shopAvgDeliveryTime = (short)Math.Round(shopModel.GetShopComments(shopComment.ShopId).Average(r => r.DeliveryTime));

            ShopRankingAttribute shopRankingAttr = shopModel.GetShopRankingAttribute(shopId);
            shopRankingAttr.Stars = shopAvgStars;
            shopRankingAttr.AveragePayMoney = shopAvgPayMoney;
            shopRankingAttr.DeliveryTime = shopAvgDeliveryTime;
            shopModel.Save();

            Shop shopInfo = shopModel.GetShop(shopId);
            userModel.AddUserPoint(userInfo.Id, "对店铺 <a href=\"/shop/detail/" + shopId + "\">" + shopInfo.Name + "</a> 发表评论", 2);
            userModel.AddUserMessage(userInfo.Id, "积分动态", "您因对店铺 <a href=\"/shop/detail/" + shopId + "\">" + shopInfo.Name + "</a>进行了评论而获得了" + 2 + "点积分。");

            return Redirect(requestUrl);
        }
Example #9
0
        public ActionResult LogOut(string returnUrl)
        {
            UserModel accountModel = new UserModel();
            accountModel.SignOut();

            if (!string.IsNullOrWhiteSpace(returnUrl) && !returnUrl.ToLower().Contains("/user"))
                return Redirect(returnUrl);

            return Redirect("/");;
        }
Example #10
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("index");

            UserModel accountModel = new UserModel();
            if (ModelState.IsValid)
            {
                var userInfo = accountModel.ValidateUser(model.UserName, model.Password);
                if (userInfo != null)
                {
                    //设置验证用户的cookie信息
                    accountModel.SignIn(userInfo, model.RememberMe);

                    if (Url.IsLocalUrl(returnUrl))
                        return Json(new { key = 1, value = returnUrl }, JsonRequestBehavior.AllowGet);
                    else
                        return Json(new { key = 1, value = "/" }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { key = 0, value = "账号或密码错误" }, JsonRequestBehavior.AllowGet);
                }
            }

            return View(model);
        }
Example #11
0
 public ActionResult Index()
 {
     UserModel userModel = new UserModel();
     var userInfo = userModel.GetUserInfoDetail(User.Identity.Name);
     ViewBag.PageName = "home";
     return View(userInfo);
 }
Example #12
0
        public ActionResult GetMsgContent(int id)
        {
            UserModel userModel = new UserModel();
            UserMessage msg = userModel.GetUserMessage(id);
            if (msg == null)
                return Json(new { key = 0, value = "该信息不存在!" }, JsonRequestBehavior.AllowGet);

            //如果该条信息没有被读过,则此时将其标记为已读
            if (!msg.Readed)
            {
                msg.Readed = true;
                userModel.Save();
            }
            return Json(new { key = 1, title = msg.MsgTitle, createTime = msg.CreateTime.ToString("yyyy/M/d HH:mm:ss"), content = msg.MsgContent }, JsonRequestBehavior.AllowGet);
        }
Example #13
0
        public ActionResult FindPassword(FindPassword formValues)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("index");

            if (ModelState.IsValid)
            {
                var emailReg = new System.Text.RegularExpressions.Regex("^(\\w)+(\\.\\w+)*@[\\w\\d]+((\\.\\w+)+)$");
                if (formValues.UserEmail == null || !emailReg.IsMatch(formValues.UserEmail))
                {
                    ModelState.AddModelError("UserEmail", "邮箱格式不正确");
                    return View(formValues);
                }
                else if (Session["ValidateCode"] == null
                   || formValues.ValidateCode == null
                   || formValues.ValidateCode.ToLower() != Session["ValidateCode"].ToString().ToLower())
                {
                    ModelState.AddModelError("ValidateCode", "验证码错误");
                    return View(formValues);
                }

                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(formValues.UserEmail);
                string newPwd = ImageValidate.CreateCode(6);//生生6位数的随机密码
                userInfo.Password = userModel.PasswordEncrypt(newPwd);
                userModel.Save();
                //发送新密码
                ZsfProject.Tools.SendEmail.ResetPassword(formValues.UserEmail, newPwd);
            }

            return RedirectToAction("FindPassword", new { step = 2 });
        }
Example #14
0
        public ActionResult Edit(int id)
        {
            ShopModel shopModel = new ShopModel();
            Shop shopBaseInfo = shopModel.GetShop(id);
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
            if(userInfo.UserGradeCategory.GradeLevel != 9 && shopBaseInfo.CreateBy != userInfo.Id)
                return Redirect("/");
            List<V_ShopDisheWithCategory> shopDisheWithCategory = shopModel.GetShopDishesWithCategory(id).OrderByDescending(r => r.DisheCategoryOrder).ToList();

            var shopCategories = shopModel.GetShopCategories();

            SelectList shopCategoryList = new SelectList(shopCategories, "Id", "Value");
            List<SelectListItem> shopCategorySelectList = shopCategoryList.ToList();

            for(int i = 0; i < shopCategorySelectList.Count; i++)
                if(shopCategorySelectList[i].Value == shopBaseInfo.CategoryId.ToString())
                {
                    shopCategorySelectList[i].Selected = true;
                    break;
                }
            ViewBag.ShopCategorySelectList = shopCategorySelectList;

            BaseDataModel baseDataModel = new BaseDataModel();
            var cityDistricts = baseDataModel.GetLocationsByParentId(214);
            ViewBag.CityDistrictSelectList = (new SelectList(cityDistricts, "Id", "Value")).ToList();

            List<ServiceArea> shopServiceAraes = shopModel.GetShopServiceAreas(id).ToList()
                .Select(r => new ServiceArea() { Id = r.AreaId, ParentId = r.ParentId, Value = r.ServiceArea, AreaType = r.AreaType }).ToList();
            ViewBag.ServiceAreaSelectList = shopServiceAraes;

            ViewBag.ShopDisheCategoryList = shopDisheWithCategory.GroupBy(r => new { r.CategoryId, r.CategoryValue })
                .Select(r => new SelectListItem() { Value = r.Key.CategoryId.ToString(), Text = r.Key.CategoryValue }).ToList();

            ViewBag.ShopLogo = Url.Content(shopImagePath + shopBaseInfo.Logo);
            ViewBag.OffsetTime = offsetTime;
            return View(new ShopDetailEditorModel(shopBaseInfo, shopDisheWithCategory));
        }
Example #15
0
        public ActionResult Register(RegisterModel registerInfo, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("index");

            if (ModelState.IsValid)
            {
                if (Session["ValidateCode"] == null || registerInfo.ValidateCode.ToLower() != Session["ValidateCode"].ToString().ToLower())
                {
                    ModelState.AddModelError("ValidateCode", "验证码错误");
                    return View(registerInfo);
                }

                UserModel userModel = new UserModel();
                UserInfo userInfo = new UserInfo();

                userInfo.Name = registerInfo.UserName;
                userInfo.Password = userModel.PasswordEncrypt(registerInfo.Password);
                userInfo.Email = registerInfo.Email;
                userInfo.GradeId = 1;
                userInfo.CreateTime = DateTime.Now;
                userInfo.Photo = "/Contents/Images/default_user_photo.png";

                userModel.Add(userInfo);

                UserMessage userMsg = new UserMessage();
                userMsg.UserId = userInfo.Id;
                userMsg.MsgTitle = "系统通知";
                userMsg.MsgContent = userInfo.Name + "欢迎您来到宅食府,希望能为您提供优质的服务。";
                userMsg.CreateTime = DateTime.Now;
                userMsg.Readed = false;
                userModel.Add(userMsg);

                userModel.SignIn(userInfo, false);
            }

            if (!string.IsNullOrWhiteSpace(returnUrl))
                return Redirect(returnUrl);

            return RedirectToAction("Index", "Shop");
        }
Example #16
0
        public ActionResult Detail(int id, int p = 1)
        {
            id = 173;
            ShopModel shopModel = new ShopModel();
            V_ShopDetail shopInfo = shopModel.GetShopDetail(id);

            if (shopInfo == null)
                return RedirectToAction("HttpError404", "Error");

            /*ShopRankingAttribute rankAttr = shopModel.GetShopRankingAttribute(id);
            rankAttr.Visits += 1;
            shopModel.Save();*/

            ViewData["ShowShopPhone"] = true;

            var shopComments = shopModel.GetShopCommentsWithUserInfo(id);
            var shopServiceAreas = shopModel.GetShopServiceAreas(id);
            var shopDishes = shopModel.GetShopDishesWithCategory(id);

            ViewBag.UserFavoriteThisShop = false;
            ViewBag.UserId = -1;
            if(User.Identity.IsAuthenticated)
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                ViewBag.UserId = userInfo.Id;
                ViewBag.UserName = userInfo.Name;
                UserFavoriteShop userFavoriteShop = userModel.GetUserFavoriteShop(id, userInfo.Id);
                if(userFavoriteShop != null)
                    ViewBag.UserFavoriteThisShop = true;
            }

            ViewBag.Id = id;
            Session["ShopDetailPhone"] = shopInfo.PhoneNumber;

            int pageSize = 5;
            int shopCommentsCount = shopComments.Count();
            ViewBag.ShopCommentsCount = shopCommentsCount;
            Paging.ToPaging(p, shopCommentsCount, this, pageSize);

            return View(new ShopDetailModel(shopInfo, shopServiceAreas, shopDishes, shopComments.Skip((p - 1) * pageSize).Take(pageSize)));
        }
Example #17
0
        public ActionResult Comments(int p = 1)
        {
            UserModel userModel = new UserModel();
            var userComments = userModel.GetUserComments(User.Identity.Name);
            int cmtCount = userComments.Count();
            ViewBag.CommentsCount = cmtCount;

            int pageSize = 15;
            Paging.ToPaging(p, cmtCount, this, pageSize);
            userComments = userComments.Skip((p - 1) * pageSize).Take(pageSize);
            ViewBag.PageName = "cmt";

            return View(userComments);
        }
Example #18
0
        public ActionResult CheckUserInfo(string type, string value)
        {
            UserModel userModel = new UserModel();
            int returnKey = 0;
            string returnValue = "";

            if (type == "name" && userModel.CheckUserName(value) != null)
                returnValue = "用户名已存在";
            else if (type == "email" && userModel.CheckUserEmail(value) != null)
                returnValue = "邮箱已存在";
            else
                returnKey = 1;

            return Json(new { key = returnKey, value = returnValue }, JsonRequestBehavior.AllowGet);
        }
Example #19
0
        public int ChangeUserServiceArea(int areaId)
        {
            string areaName = "";

            if (User.Identity.IsAuthenticated)
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                UserDefaultArea defaultArea;
                if (userInfo.UserDefaultArea.Count == 0)
                {
                    defaultArea = new UserDefaultArea();
                    defaultArea.UserId = userInfo.Id;
                    defaultArea.AreaId = areaId;
                    userModel.Add(defaultArea);
                }
                else
                {
                    defaultArea = userModel.GetUserDefaultArea(userInfo.Id);
                    defaultArea.AreaId = areaId;
                    userModel.Save();
                }
                areaName = defaultArea.ServiceArea.Value;
            }
            else
            {
                BaseDataModel baseModel = new BaseDataModel();
                areaName =  baseModel.GetServiceArea(areaId).Value;
            }

            System.Web.HttpCookie areaCookie = new System.Web.HttpCookie("udefaultarea");
            areaCookie.Domain = BaseDataModel.CookieDomain;
            areaCookie.Values["Id"] = areaId.ToString();
            areaCookie.Values["Name"] = HttpUtility.UrlEncode(areaName);
            areaCookie.Expires = DateTime.Now.AddYears(1);
            Response.Cookies.Set(areaCookie);
            return 1;
        }
Example #20
0
        public ActionResult Search(string shopName, int categoryId = 0, int p = 1, string s = "default")
        {
            ViewBag.ShopSearchName = shopName;
            ShopModel shopModel = new ShopModel();
            string serviceAreaId = "0";//默认宁波大学
            string serviceAreaName = "";
            UserModel.GetUserDefaultAreaSetting(ref serviceAreaId, ref serviceAreaName);

            var shops = shopModel.GetShopsList(shopName, int.Parse(serviceAreaId));
            List<V_UserFavoriteShopForList> favoriteShops = new List<V_UserFavoriteShopForList>();
            if(User.Identity.IsAuthenticated)
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                favoriteShops = shopModel.GetFavoriteShopsList(userInfo.Id).ToList();
            }

            var shopCategories = shopModel.GetShopCategoryStatistic(shops);

            ViewBag.TotalShopsCount = shops.Count();

            if(categoryId != 0)
            {
                shops = shops.Where(r => r.CategoryId == categoryId);
                ViewBag.ShopsCount = shops.Count();
            }
            else
                ViewBag.ShopsCount = ViewBag.TotalShopsCount;

            ViewBag.CategoryId = categoryId;

            switch(s.ToLower())
            {
                case "grade":
                    shops = shops.OrderByDescending(r => r.Stars);
                    break;
                case "price":
                    shops = shops.OrderBy(r => r.UpSendPrice);
                    break;
                case "speed":
                    shops = shops.OrderBy(r => r.DeliveryTime);
                    break;
                case "paymoney":
                    shops = shops.OrderBy(r => r.AveragePayMoney);
                    break;
            }
            ViewBag.SortBy = s;

            int pageSize = Request.Browser.IsMobileDevice ? 15 : 25;
            Paging.ToPaging(p, ViewBag.ShopsCount, this, pageSize);
            shops = shops.Skip((p - 1) * pageSize).Take(pageSize);
            return View(new ShopsListModel(shopCategories, shops, favoriteShops));
        }
Example #21
0
        public ActionResult Edit(string shopData)
        {
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
            ShopModel shopModel = new ShopModel();
            var jser = new System.Web.Script.Serialization.JavaScriptSerializer();
            ShopEditorObject shopDataObj = jser.Deserialize<ShopEditorObject>(shopData);
            ShopWithSAObject newShopInfo = shopDataObj.ShopBaseInfo;
            int shopId = newShopInfo.Id;

            Shop shopInfo = shopModel.GetShop(shopId);
            if(userInfo.UserGradeCategory.GradeLevel != 9 && userInfo.Id != shopInfo.CreateBy)
                return Redirect("/");
            shopInfo.Name = newShopInfo.Name;
            shopInfo.Address = newShopInfo.Address;
            shopInfo.PhoneNumber = newShopInfo.PhoneNumber;
            shopInfo.CategoryId = newShopInfo.CategoryId;
            shopInfo.OfficeTimeBegin = newShopInfo.OfficeTimeBegin;
            shopInfo.OfficeTimeEnd = newShopInfo.OfficeTimeEnd;
            shopInfo.UpSendPrice = newShopInfo.UpSendPrice;
            shopInfo.Remark = newShopInfo.Remark;
            shopInfo.Latitude = newShopInfo.Latitude;
            shopInfo.Longitude = newShopInfo.Longitude;
            shopInfo.LastModifyAt = DateTime.Now;
            shopInfo.LastModifyBy = userInfo.Id;

            if (!String.IsNullOrWhiteSpace(newShopInfo.Logo))
            {
                string sourcePath = Server.MapPath(newShopInfo.Logo);
                string fileName = Path.GetFileName(sourcePath);
                if (!System.IO.File.Exists(Server.MapPath("~/Contents/ShopImages/") + fileName))
                    System.IO.File.Move(sourcePath, Server.MapPath("~/Contents/ShopImages/") + fileName);
                newShopInfo.Logo = fileName;
            }
            else
                newShopInfo.Logo = new Random().Next(1, 7) + ".jpg";
            shopInfo.Logo = newShopInfo.Logo;
            shopModel.Save();

            ShopModifyLog editLog = new ShopModifyLog();
            editLog.ShopId = shopId;
            editLog.ModifyBy = userInfo.Id;
            editLog.ModifyAt = DateTime.Now;
            shopModel.Add(editLog);

            shopModel.DeleteShopServiceAreas(shopId);
            if (newShopInfo.ServiceAreas != null)
            {
                foreach (int saItem in newShopInfo.ServiceAreas)
                {
                    ShopServiceArea shopServiceArea = new ShopServiceArea();
                    shopServiceArea.ShopId = shopId;
                    shopServiceArea.AreaId = saItem;
                    shopModel.AddWithoutSave(shopServiceArea);
                }
                shopModel.Save();
            }

            shopModel.DeleteDisheCategories(shopId);
            shopModel.DeleteDishes(shopId);
            List<DisheWithCategoryDetailObject> disheWithCats = shopDataObj.DisheWithCategoryDetail;
            foreach (DisheWithCategoryDetailObject dwcItem in disheWithCats)
            {
                ShopDisheCategory disheCategory = new ShopDisheCategory();
                disheCategory.ShopId = shopId;
                disheCategory.Value = dwcItem.CategoryName;
                shopModel.Add(disheCategory);

                foreach (ShopDishe disheItem in dwcItem.Dishes)
                {
                    ShopDishe dishe = disheItem;
                    dishe.ShopId = shopId;
                    dishe.CategoryId = disheCategory.Id;
                    shopModel.AddWithoutSave(dishe);
                }
                shopModel.Save();
            }

            return Json(new { status = 1, url = "/shop/detail/" + shopId }, JsonRequestBehavior.AllowGet);
        }
Example #22
0
        public ActionResult Messages(int p = 1)
        {
            UserModel userModel = new UserModel();
            var userMails = userModel.GetUserMessages(User.Identity.Name);
            int msgCount = userMails.Count();
            ViewBag.MessagesCount = msgCount;

            int pageSize = 15;
            Paging.ToPaging(p, msgCount, this, pageSize);
            userMails = userMails.Skip((p - 1) * pageSize).Take(pageSize);
            ViewBag.PageName = "msg";

            return View(userMails);
        }
Example #23
0
        public ActionResult Points(int p = 1, bool u = true)
        {
            UserModel userModel = new UserModel();
            var userPoints = userModel.GetUserPoints(User.Identity.Name, u);
            int pointCount = userPoints.Count();
            ViewBag.UsablePointsCount = userModel.GetUserTotalUsablePoint(User.Identity.Name);
            ViewBag.PointUsable = u;

            int pageSize = 15;
            Paging.ToPaging(p, pointCount, this, pageSize);
            userPoints = userPoints.Skip((p - 1) * pageSize).Take(pageSize);
            ViewBag.PageName = "point";

            return View(userPoints);
        }
Example #24
0
        public void Join(int userId, int shopId)
        {
            List<OrderDetail> orders = new List<OrderDetail>();
            ShopModel sm = new ShopModel();
            UserModel um = new UserModel();

            UserInfo userInfo = um.GetUserInfo(userId);
            short userGradeLevel = userInfo.UserGradeCategory.GradeLevel;

            ClientInfo clientInfo = new ClientInfo()
            { ConnectionId = Context.ConnectionId, UserId = userId, UserName = userInfo.Name, GradeLevel = userGradeLevel };

            if (_ClientInfos.Any(r => r.Key == userId))
            {
                _ClientInfos[userId] = clientInfo;
            }
            else
            {
                _ClientInfos[userId] = clientInfo;
            }

            if (_Managers.Any(r => r == Context.ConnectionId))
            {
                if (userGradeLevel != 9)
                {
                    _Managers.Remove(Context.ConnectionId);
                }
            }
            else
            {
                if (userGradeLevel == 9)
                {
                    _Managers.Add(Context.ConnectionId);
                }
            }

            orders = sm.GetAvailableUserOrderDetail(shopId)
                .Select(r => new OrderDetail()
                {
                    Id = r.Id,
                    DisheId = r.DisheId,
                    Count = r.OrderCount,
                    Price = r.Price,
                    Available = (r.UserId == userId || userGradeLevel == 9) ? 1 : 0
                }).ToList<OrderDetail>();

            Clients.Caller.broadcastOrderAdd(orders);
        }
Example #25
0
        public ActionResult CropUserPhoto(string imgPath, float zoomRatio, float cropX, float cropY, int cropW, int cropH)
        {
            string fileName = "";
            string filePath = "";
            using (Image logo = Image.FromFile(Server.MapPath(imgPath)))
            {
                //根据缩放比例,剪切原图中对应的区域
                RectangleF cropRec = new RectangleF(cropX / zoomRatio, cropY / zoomRatio, cropW / zoomRatio, cropH / zoomRatio);
                //将剪切后的图片填充到该矩形内
                Rectangle fillRec = new Rectangle(0, 0, cropW, cropH);

                using (Bitmap logoBit = new Bitmap(cropW, cropH))
                {
                    using (Graphics g = Graphics.FromImage(logoBit))
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.DrawImage(logo, fillRec, cropRec, GraphicsUnit.Pixel);

                        UserModel userModel = new UserModel();
                        UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                        string fileExtension = Path.GetExtension(imgPath);

                        filePath = Path.GetDirectoryName(Server.MapPath("~/Contents/UserPhotos/"));
                        fileName = (10200 + userInfo.Id) + fileExtension;
                        string fileFullPath = filePath + "\\" + fileName;

                        if (System.IO.File.Exists(fileFullPath))
                        {
                            try
                            {
                                System.IO.File.Delete(fileFullPath);
                            }
                            catch
                            {//如果删除不成功,就以随机的GUID来命名文件
                                fileName = Guid.NewGuid().ToString() + fileExtension;
                                fileFullPath = filePath + "\\" + fileName;
                            }
                        }
                        userInfo.Photo = "/Contents/UserPhotos/" + fileName;
                        userModel.Save();

                        logoBit.Save(fileFullPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
            }

            return Json(new { key = 1, value = "/Contents/UserPhotos/" + fileName }, JsonRequestBehavior.AllowGet);
        }
Example #26
0
        public ActionResult CreateNewUserOrder()
        {
            ShopModel sm = new ShopModel();
            UserModel um = new UserModel();

            int availableOrderId = sm.GetAvailableUserOrderId();

            if(availableOrderId != -1)
                return Json(new { status = 0, msg = availableOrderId }, JsonRequestBehavior.AllowGet);

            UserOrder order = new UserOrder();

            UserInfo userInfo = um.GetUserInfo(User.Identity.Name);
            order.Available = true;
            order.CreateBy = userInfo.Id;
            order.CreateTime = DateTime.Now;
            try
            {
                sm.Add(order);
            }
            catch(Exception ex)
            {
                return Json(new { status = 0, msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { status = 1, msg = order.Id }, JsonRequestBehavior.AllowGet);
        }
Example #27
0
        public ActionResult ChangeUserInfo(bool gender, string birthDay)
        {
            try
            {
                if (!User.Identity.IsAuthenticated)
                    return Json(new { key = 0, value = "用户不合法!" }, JsonRequestBehavior.AllowGet);

                UserModel userModel = new UserModel();
                var userInfo = userModel.GetUserInfo(User.Identity.Name);
                userInfo.Gender = gender;
                userInfo.Birthday = DateTime.Parse(birthDay);
                userModel.Save();
                return Json(new { key = 1, value = "修改成功!" }, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(new { key = 0, value = "网站内部错误!请刷新页面重试。" }, JsonRequestBehavior.AllowGet);
            }
        }
Example #28
0
        public ActionResult FavoriteShops(int p = 1)
        {
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
            var favoriteShops = userModel.GetUserFavoriteShops(userInfo.Id);
            int favCount = favoriteShops.Count();
            ViewBag.FavoriteShopsCount = favCount;

            int pageSize = 16;
            Paging.ToPaging(p, favCount, this, pageSize);
            favoriteShops = favoriteShops.Skip((p - 1) * pageSize).Take(pageSize);
            ViewBag.PageName = "favshop";

            return View(favoriteShops);
        }
Example #29
0
        public void AddNewOrderDetail(int userId, OrderDetail orderDetail)
        {
            UserOrderDetail order = new UserOrderDetail();
            ShopModel sm = new ShopModel();
            int orderId = sm.GetAvailableUserOrderId();

            try
            {
                UserModel um = new UserModel();
                UserInfo userInfo = um.GetUserInfo(userId);

                order.OrderId = orderId;
                order.DisheId = orderDetail.DisheId;
                order.ShopId = orderDetail.ShopId;
                order.UserId = userInfo.Id;
                order.Price = orderDetail.Price;
                order.OrderCount = orderDetail.Count;
                order.CreateDate = DateTime.Now;

                sm.Add(order);

                orderDetail.Id = order.Id;

                orderDetail.Available = 1;
            }
            catch (Exception ex)
            {

            }

            orderDetail.Available = 1;
            List<string> managers = _ClientInfos.Where(r => r.Value.GradeLevel == 9 || r.Key == userId)
                .Select(r => r.Value.ConnectionId).ToList();

            Clients.Clients(managers).broadcastOrderAdd(new List<OrderDetail> { orderDetail });

            orderDetail.Available = 0;
            Clients.AllExcept(managers.ToArray()).broadcastOrderAdd(new List<OrderDetail> { orderDetail });
        }
Example #30
0
        public ActionResult Create(string shopData)
        {
            ShopModel shopModel = new ShopModel();
            var jser = new System.Web.Script.Serialization.JavaScriptSerializer();
            ShopEditorObject shopDataObj = jser.Deserialize<ShopEditorObject>(shopData);
            ShopWithSAObject newShopInfo = shopDataObj.ShopBaseInfo;
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

            Shop shopInfo = new Shop();
            shopInfo.Name = newShopInfo.Name;
            shopInfo.Address = newShopInfo.Address;
            shopInfo.PhoneNumber = newShopInfo.PhoneNumber;
            shopInfo.CategoryId = newShopInfo.CategoryId;
            shopInfo.OfficeTimeBegin = newShopInfo.OfficeTimeBegin;
            shopInfo.OfficeTimeEnd = newShopInfo.OfficeTimeEnd;
            shopInfo.UpSendPrice = newShopInfo.UpSendPrice;
            shopInfo.Remark = newShopInfo.Remark;
            shopInfo.Latitude = newShopInfo.Latitude;
            shopInfo.Longitude = newShopInfo.Longitude;
            shopInfo.CreateTime = DateTime.Now;
            shopInfo.LastModifyAt = shopInfo.CreateTime;
            shopInfo.CreateBy = userInfo.Id;
            shopInfo.LastModifyBy = shopInfo.CreateBy;
            shopInfo.Hidden = true;
            if (!String.IsNullOrWhiteSpace(newShopInfo.Logo))
            {
                string sourcePath = Server.MapPath(newShopInfo.Logo);
                string fileName = Path.GetFileName(sourcePath);
                if (!System.IO.File.Exists(Server.MapPath("~/Contents/ShopImages/") + fileName))
                    System.IO.File.Move(sourcePath, Server.MapPath("~/Contents/ShopImages/") + fileName);
                newShopInfo.Logo = fileName;
            }
            else
                newShopInfo.Logo = new Random().Next(1, 7) + ".jpg";
            shopInfo.Logo = newShopInfo.Logo;
            shopModel.Add(shopInfo);
            shopModel.Save();

            int shopId = shopInfo.Id;

            shopModel.DeleteShopServiceAreas(shopId);
            if (newShopInfo.ServiceAreas != null)
            {
                foreach (int saItem in newShopInfo.ServiceAreas)
                {
                    ShopServiceArea shopServiceArea = new ShopServiceArea();
                    shopServiceArea.ShopId = shopId;
                    shopServiceArea.AreaId = saItem;
                    shopModel.AddWithoutSave(shopServiceArea);
                }
                shopModel.Save();
            }
            try
            {
                shopModel.DeleteDisheCategories(shopId);
                shopModel.DeleteDishes(shopId);
                double totalPrice = 0;
                List<DisheWithCategoryDetailObject> disheWithCats = shopDataObj.DisheWithCategoryDetail;
                foreach(DisheWithCategoryDetailObject dwcItem in disheWithCats)
                {
                    ShopDisheCategory disheCategory = new ShopDisheCategory();
                    disheCategory.ShopId = shopId;
                    disheCategory.Value = dwcItem.CategoryName;
                    shopModel.Add(disheCategory);

                    foreach(ShopDishe disheItem in dwcItem.Dishes)
                    {
                        ShopDishe dishe = disheItem;
                        dishe.ShopId = shopId;
                        dishe.CategoryId = disheCategory.Id;
                        shopModel.AddWithoutSave(dishe);
                        totalPrice += dishe.Price;
                    }
                    shopModel.Save();
                }

                ShopRankingAttribute rankingAttribute = new ShopRankingAttribute();
                rankingAttribute.ShopId = shopId;
                rankingAttribute.Stars = 0;
                rankingAttribute.AveragePayMoney = (short)(totalPrice / disheWithCats.Select(r => r.Dishes.Count).Sum(r => r));
                rankingAttribute.DeliveryTime = 30;
                shopModel.Add(rankingAttribute);
            }
            catch(Exception ex)
            {
                return Json(new { status = 0, data = ex.InnerException }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { status = 1, url = "/shop/detail/" + shopId }, JsonRequestBehavior.AllowGet);
        }