Ejemplo n.º 1
0
        public ActionResult Create(PhotoGroups photogroups)
        {
            if (ModelState.IsValid)
            {
                photogroups.publishTime = DateTime.Now;
                var temp = db.PhotoGroups.Select(s => s.orderNum).Max();
                var urls = Request["imgurls"];
                photogroups.orderNum = temp + 1;
                if (!string.IsNullOrWhiteSpace(urls))
                {
                    photogroups.imgTitle = urls.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0];
                }
                db.PhotoGroups.Add(photogroups);
                db.SaveChanges();

                //int albumId = photogroups.id;
                foreach (var img in urls.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    Photos p = new Photos();
                    p.title       = photogroups.title;
                    p.content     = photogroups.content;
                    p.photoGroup  = photogroups.id;
                    p.publishTime = DateTime.Now;
                    p.imgurls     = img;
                    p.orderNum    = 1;
                    db.Photos.Add(p);
                }

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(photogroups));
        }
Ejemplo n.º 2
0
        public ActionResult Create(Photos photos)
        {
            if (ModelState.IsValid)
            {
                db.Photos.Add(photos);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photos));
        }
Ejemplo n.º 3
0
        public ActionResult Create(Essays essays)
        {
            if (ModelState.IsValid)
            {
                var temp = db.Essays.Select(s => s.orderNum).Max();
                essays.orderNum    = temp + 1;
                essays.publishTime = DateTime.Now;
                db.Essays.Add(essays);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(essays));
        }
Ejemplo n.º 4
0
        public ActionResult Create(Sources sources)
        {
            if (ModelState.IsValid)
            {
                var temp = db.Sources.Select(s => s.orderNum).Max();
                sources.orderNum      = temp + 1;
                sources.downloadCount = 0;
                sources.author        = "zuorx";
                sources.publishTime   = DateTime.Now;
                db.Sources.Add(sources);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(sources));
        }
Ejemplo n.º 5
0
        public int Dowload(int id = 0)
        {
            Sources source = db.Sources.Find(id);

            if (source == null)
            {
                return(0);
            }
            source.downloadCount  += 1;
            db.Entry(source).State = EntityState.Modified;
            db.SaveChanges();
            return(source.downloadCount);
        }
Ejemplo n.º 6
0
        public void LogMaintenance()
        {
            Logs log = new Logs();

            log.logtype    = "用户访问";
            log.logcontent = "用户访问";
            log.logtime    = DateTime.Now;
            log.loguser    = "";
            log.logip      = IpSupport.GetClientIp();
            log.logfree    = IpSupport.GetAdrByIp(log.logip);
            db.Logs.Add(log);
            db.SaveChanges();
        }
Ejemplo n.º 7
0
        public ActionResult GoogleLoginCallback()
        {
            var claimsPrincipal = HttpContext.User.Identity as ClaimsIdentity;

            var loginInfo = GoogleLoginViewModel.GetLoginInfo(claimsPrincipal);

            if (loginInfo == null)
            {
                return(RedirectToAction("Index"));
            }


            WebEntities db   = new WebEntities(); //DbContext
            var         user = db.UserAccounts.FirstOrDefault(x => x.Email == loginInfo.emailaddress);

            if (user == null)
            {
                user = new UserAccount
                {
                    Email      = loginInfo.emailaddress,
                    GivenName  = loginInfo.givenname,
                    Identifier = loginInfo.nameidentifier,
                    Name       = loginInfo.name,
                    SurName    = loginInfo.surname,
                    IsActive   = true
                };
                db.UserAccounts.Add(user);
                db.SaveChanges();
            }

            var ident = new ClaimsIdentity(
                new[] {
                // adding following 2 claim just for supporting default antiforgery provider
                new Claim(ClaimTypes.NameIdentifier, user.Email),
                new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),

                new Claim(ClaimTypes.Name, user.Name),
                new Claim(ClaimTypes.Email, user.Email),
                // optionally you could add roles if any
                new Claim(ClaimTypes.Role, "User")
            },
                CookieAuthenticationDefaults.AuthenticationType);


            HttpContext.GetOwinContext().Authentication.SignIn(
                new AuthenticationProperties {
                IsPersistent = false
            }, ident);
            return(Redirect("~/"));
        }
Ejemplo n.º 8
0
        public ActionResult Create(Blogs blogs)
        {
            if (ModelState.IsValid)
            {
                var      temp    = db.Blogs.Select(s => s.orderNum).Max();
                string   tempStr = "";
                string[] imgs    = HtmlSupport.GetHtmlImageUrlList(blogs.content);

                foreach (var str in imgs)
                {
                    tempStr += str + "|";
                }
                blogs.imgurls     = (!string.IsNullOrEmpty(tempStr) ? tempStr.Substring(0, tempStr.Length - 1) : "/upload/image/blog/20160101/def.jpg");
                blogs.orderNum    = temp + 1;
                blogs.viewCount   = 0;
                blogs.author      = "zuorx";
                blogs.publishTime = DateTime.Now;
                db.Blogs.Add(blogs);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(blogs));
        }
Ejemplo n.º 9
0
        //public ActionResult Search(string searchKey = "", int pageIndex = 1)
        //{
        //    searchKey=searchKey.ToUpper();
        //    int pageSize = 3;
        //    //从数据库在取得数据,并返回总记录数
        //    var temp = from d in db.Blogs
        //               select d;
        //    temp = temp.Where<Blog>(s => s.title.Contains(searchKey) || s.content.Contains(searchKey) ||
        //        s.author.Contains(searchKey) || s.keyword.Contains(searchKey));
        //    int count = temp.Count();
        //    var tag = from d in db.Blogs
        //              select d.keyword;
        //    List<string> list = new List<string>();
        //    foreach (var item in tag)
        //    {
        //        list.AddRange(item.Split('|'));
        //    }
        //    var best = from d in db.Blogs
        //               orderby d.viewCount descending
        //               select d;
        //    BlogRight<IEnumerable<string>, IQueryable<Blog>> blogright =
        //        new BlogRight<IEnumerable<string>, IQueryable<Blog>>(list.Distinct<string>(), best.Take(5));
        //    PagerInfo pager = new PagerInfo();
        //    pager.CurrentPageIndex = pageIndex;
        //    pager.PageSize = pageSize;
        //    pager.RecordCount = count;
        //    PagerQuery<PagerInfo, IQueryable<Blog>, BlogRight<IEnumerable<string>, IQueryable<Blog>>> query
        //        = new PagerQuery<PagerInfo, IQueryable<Blog>, BlogRight<IEnumerable<string>,
        //            IQueryable<Blog>>>(pager, temp.OrderByDescending(s => s.publishTime).Skip<Blog>((pageIndex - 1) * pageSize).Take<Blog>(pageSize), blogright);
        //    return View("Index",query);
        //}

        //
        // GET: /Blog/Details/5

        public ActionResult Details(int id = 0)
        {
            ViewBag.skin = GlobalVar.skin;
            Blogs blog = db.Blogs.Find(id);

            if (blog == null)
            {
                return(HttpNotFound());
            }
            Blogs before = db.Blogs.Where(s => s.id < id).OrderByDescending(s => s.id).FirstOrDefault();
            Blogs after  = db.Blogs.Where(s => s.id > id).OrderBy(s => s.id).FirstOrDefault();

            before               = (before == null ? blog : before);
            after                = (after == null ? blog : after);
            blog.viewCount      += 1;
            db.Entry(blog).State = EntityState.Modified;
            db.SaveChanges();

            List <Blogs> blogs = new List <Blogs>();

            blogs.Add(blog);
            blogs.Add(before);
            blogs.Add(after);
            var tag = from d in db.Blogs
                      select d.keyword;
            List <string> list = new List <string>();

            foreach (var item in tag)
            {
                list.AddRange(item.Split('|'));
            }
            var best = from d in db.Blogs
                       orderby d.viewCount descending
                       select d;
            BlogRight <IEnumerable <string>, IQueryable <Blogs> > blogright =
                new BlogRight <IEnumerable <string>, IQueryable <Blogs> >(list.Distinct <string>(), best.Take(5));
            DetailQuery <List <Blogs>, BlogRight <IEnumerable <string>, IQueryable <Blogs> > > query
                = new DetailQuery <List <Blogs>, BlogRight <IEnumerable <string>,
                                                            IQueryable <Blogs> > >(blogs, blogright);

            return(View(query));
        }
Ejemplo n.º 10
0
        public ActionResult LoginCheck(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && LoginCk(model.UserName, model.Password))
            {
                Session.Add("username", model.UserName);
                Session.Add("password", model.Password);
                Logs log = new Logs();
                log.logtype    = "控制台登陆";
                log.logcontent = "控制台登陆";
                log.logtime    = DateTime.Now;
                log.loguser    = model.UserName;
                log.logip      = IpSupport.GetClientIp();
                db.Logs.Add(log);
                db.SaveChanges();
                return(RedirectToAction("Index", "Console"));
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            ModelState.AddModelError("", "提供的用户名或密码不正确。");
            return(View("Index", model));
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> Create(RegisterViewModel userViewModel, string[] actions, params string[] selectedRoles)
        {
            var menus = _db.BackendMenu.Select(s => new BackendMenuViewModel()
            {
                MenuId = s.MenuId,
                Name   = s.Name,
                /* Permissions = _db.BackendMenuAction.Where(x => x.MenuId == s.MenuId)*/
                Actions = s.BackendMenuAction.ToList().Select(x => new SelectListItem()
                {
                    Text  = x.Name,
                    Value = x.ActionId.ToString()
                })
            }).AsEnumerable();



            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = userViewModel.Email, Email = userViewModel.Email, NickName = userViewModel.NickName
                };
                var adminresult = await UserManager.CreateAsync(user, userViewModel.Password);

                //Add User to the selected Roles
                if (adminresult.Succeeded)
                {
                    if (actions != null)
                    {
                        foreach (var action in actions)
                        {
                            short actionId = Convert.ToInt16(action);
                            _db.BackendUserPermission.Add(new BackendUserPermission()
                            {
                                ActionId = actionId,
                                UserId   = user.Id
                            });
                        }

                        _db.SaveChanges();
                    }

                    if (selectedRoles != null)
                    {
                        var result = await UserManager.AddToRolesAsync(user.Id, selectedRoles);

                        if (!result.Succeeded)
                        {
                            ModelState.AddModelError("", result.Errors.First());
                            ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name");

                            userViewModel.Menus = menus;

                            return(View(userViewModel));

                            //return View();
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", adminresult.Errors.First());
                    ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");

                    userViewModel.Menus = menus;

                    return(View(userViewModel));
                    //return View();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.RoleId      = new SelectList(RoleManager.Roles, "Name", "Name");
            userViewModel.Menus = menus;

            return(View(userViewModel));
            //return View();
        }
Ejemplo n.º 12
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new WebEntities())
     {
         try
         {
             var myItem = (from c in _db.SanPhamDuocChons where c.IDGioHang == updateCartID && c.SanPham.ID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.SoLuong = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Ejemplo n.º 13
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new WebEntities())
     {
         try
         {
             var myItem = (from c in _db.SanPhamDuocChons where c.IDGioHang == removeCartID && c.SanPham.ID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.SanPhamDuocChons.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }