Exemplo n.º 1
0
 public ActionResult PreferEdit(PreferModels form)
 {
     if (ModelState.IsValid)
     {
         Prefer pp = PreferRepository.GetByKey(form.ID);
         pp.Name = form.Name;
         pp.Content = form.Content;
         pp.Explanation = form.Explanation;
         pp.ImageUrl = form.ImageUrl;
         pp.WURL = form.WURL;
         if (form.StartDate == null)
         {
             pp.StartDate = DateTime.Now;
         }
         if (form.EndDate == null)
         {
             pp.EndDate = DateTime.Now;
         }
         pp.ClubName = form.ClubName;
         PreferRepository.Update(pp);
         PreferRepository.Context.Commit();
     }
     return Redirect("/Prefer/PreferIndex");
 }
Exemplo n.º 2
0
        public ActionResult PreferCreate(PreferModels form)
        {
            var UserId = WebSecurity.GetUserId(User.Identity.Name);
            var user = UserProfileRepository.Find(Specification<EasyWeixin.Model.UserProfile>.Eval(o => o.UserId == UserId));
            form.UserId = WebSecurity.GetUserId(User.Identity.Name);
            form.AddDate = DateTime.Now;
            form.Clicks = 0;
            form.IsTop = 0;
            form.TopTime = null;
            form.CreateIp = Request.UserHostAddress;

            if (form.StartDate == null)
            {
                form.StartDate = DateTime.Now;
            }
            if (form.EndDate == null)
            {
                form.EndDate = DateTime.Now;
            }

            if (string.IsNullOrEmpty(form.ImageUrl))
            {
                form.ImageUrl = GetImageUrl(form.Content);
            }
            if (ModelState.IsValid)
            {
                Prefer pp = Mapper.Map<PreferModels, Prefer>(form);
                PreferRepository.Add(pp);
                PreferRepository.Context.Commit();
                switch (UserId.ToString())
                {
                    case "28":
                        //上海
                        pp.GetURL = "http://" + Request.Url.Host + "/ActivityPrefer/PreferIndex?PreferID=" + pp.ID + "&User_ID=" + user.ID;
                        break;

                    case "27":
                        //天津
                        pp.GetURL = "http://" + Request.Url.Host + "/ActivityPrefer/TPreferIndex?PreferID=" + pp.ID + "&User_ID=" + user.ID;
                        break;

                    case "29":
                        //武汉
                        pp.GetURL = "http://" + Request.Url.Host + "/ActivityPrefer/WPreferIndex?PreferID=" + pp.ID + "&User_ID=" + user.ID;
                        break;

                    case "32":
                        //云南
                        pp.GetURL = "http://" + Request.Url.Host + "/ActivityPrefer/YPreferIndex?PreferID=" + pp.ID + "&User_ID=" + user.ID;
                        break;

                    case "31":
                        //泰州
                        pp.GetURL = "http://" + Request.Url.Host + "/ActivityPrefer/ZPreferIndex?PreferID=" + pp.ID + "&User_ID=" + user.ID;
                        break;

                    default:
                        pp.GetURL = "http://" + Request.Url.Host + "/ActivityPrefer/PreferIndex?PreferID=" + pp.ID + "&User_ID=" + user.ID;
                        break;
                }

                PreferRepository.Update(pp);
                PreferRepository.Context.Commit();
            }
            return Redirect("/Prefer/PreferIndex");
        }