Exemple #1
0
        public ActionResult Create([Bind(Include = "ID,RoleID,MenuText,IDParentMenu,IconMenu,OrderSort")] MenuApp menuApp)
        {
            if (ModelState.IsValid)
            {
                db.MenuApp.Add(menuApp);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.parent = db.MenuApp.Where(a => a.IDParentMenu == null).ToList();
            ViewBag.RoleID = new SelectList(db.Roles, "id", "name", menuApp.RoleID);
            return(View("~/Views/appdashboard/masterdata/Menu/Add.cshtml", menuApp));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "id,id_group,id_parent,remark")] GroupLevel groupLevel)
        {
            if (ModelState.IsValid)
            {
                db.GroupLevel.Add(groupLevel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.parent   = db.GroupLevel.Include(g => g.GroupLevel2).Include(g => g.Groups).Where(a => a.id_parent == null).ToList();
            ViewBag.id_group = new SelectList(db.Groups, "id", "name", groupLevel.id_group);
            return(View("~/Views/appdashboard/adminsystem/GroupLevel/Add.cshtml", groupLevel));
        }
Exemple #3
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         TryUpdateModel(collection);
         using (var myAppEntities = new MyAppEntities())
         {
             if (collection.AllKeys.Contains("key"))
             {
                 var    key   = collection.GetValue("key").AttemptedValue;
                 var    val   = collection.GetValue("val").AttemptedValue;
                 string query = "update Roles set " + key + " = '" + val + "' where id = '" + id + "'";
                 myAppEntities.UserRole.SqlQuery(query).FirstOrDefault();
             }
             else
             {
                 var m = myAppEntities.Roles.Where(a => a.id == id).FirstOrDefault();
                 TryUpdateModel(m);
                 myAppEntities.SaveChanges();
             }
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         MyAppEntities myAppEntities = new MyAppEntities();
         var           model         = myAppEntities.Roles.Where(a => a.id == id).FirstOrDefault();
         return(View("~/Views/appdashboard/masterdata/Role/Edit.cshtml", model));
     }
 }
Exemple #4
0
        public MyAppApiResult <MemberShip> Regist(MemberShip user)
        {
            var res = new MyAppApiResult <MemberShip>();

            try
            {
                using (var db = new MyAppEntities())
                {
                    #region
                    if (db.MemberShip.Any(o => o.LoginName == user.LoginName))
                    {
                        res.AddError("用户已存在");
                        return(res);
                    }
                    #endregion
                    user.Id = Guid.NewGuid();
                    db.MemberShip.Add(user);
                    db.SaveChanges();
                    res.Data = user;
                }
            }
            catch (Exception e)
            {
                res.AddError(e.Message);
            }
            return(res);
        }
        public MyAppApiResult <bool> AddArticle(MyApp_Article article)
        {
            var result = new MyAppApiResult <bool>();

            try
            {
                #region
                if (String.IsNullOrEmpty(article.AritcleName) || String.IsNullOrEmpty(article.SimpleText) || article.Type == null)
                {
                    result.AddError("数据不全,请确认后提交");
                    return(result);
                }
                #endregion
                var db = new MyAppEntities();
                article.Id              = Guid.NewGuid();
                article.WriteTime       = DateTime.Now;
                article.AritcleAuthorId = Guid.NewGuid();
                db.MyApp_Article.Add(article);
                db.SaveChanges();
            }
            catch (Exception e) {
                result.AddError(e.Message);
            }
            return(result);
        }
        public MyAppApiResult <MyApp_Article> GetArticalById(Guid Id, MemberShip CurrentUser)
        {
            var result = new MyAppApiResult <MyApp_Article>();

            try
            {
                using (var db = new MyAppEntities())
                {
                    result.Data = db.MyApp_Article.FirstOrDefault(o => o.Id == Id);
                    if (!db.MyApp_LookLog.Any(o => o.MemberShipId == CurrentUser.Id && o.ArticleId == Id))
                    {
                        db.MyApp_LookLog.Add(new MyApp_LookLog()
                        {
                            Id           = Guid.NewGuid(),
                            MemberShipId = CurrentUser.Id,
                            ArticleId    = Id
                        });
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }
            return(result);
        }
Exemple #7
0
 public ActionResult Create(Roles collection)
 {
     try
     {
         TryUpdateModel(collection);
         using (var myAppEntities = new MyAppEntities())
         {
             myAppEntities.Roles.Add(collection);
             myAppEntities.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View("~/Views/appdashboard/masterdata/Role/Add.cshtml"));
     }
 }
Exemple #8
0
 public ActionResult Create(Users collection)
 {
     try
     {
         collection.password = BCrypt.Net.BCrypt.HashPassword(collection.password);
         TryUpdateModel(collection);
         using (var myAppEntities = new MyAppEntities())
         {
             myAppEntities.Users.Add(collection);
             myAppEntities.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View("~/Views/appdashboard/adminsystem/User/Add.cshtml"));
     }
 }
Exemple #9
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         TryUpdateModel(collection);
         using (var myAppEntities = new MyAppEntities())
         {
             var m = myAppEntities.Roles.Remove(myAppEntities.Roles.FirstOrDefault(x => x.id == id));
             TryUpdateModel(m);
             myAppEntities.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         MyAppEntities myAppEntities = new MyAppEntities();
         var           model         = myAppEntities.Roles.Where(a => a.id == id).FirstOrDefault();
         return(View("~/Views/appdashboard/masterdata/Role/Delete.cshtml", model));
     }
 }
Exemple #10
0
 public ActionResult Edit(int id, Groups collection)
 {
     try
     {
         TryUpdateModel(collection);
         using (var myAppEntities = new MyAppEntities())
         {
             var m = myAppEntities.Groups.Where(a => a.id == id).FirstOrDefault();
             TryUpdateModel(m);
             myAppEntities.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         MyAppEntities myAppEntities = new MyAppEntities();
         var           model         = myAppEntities.Groups.Where(a => a.id == id).FirstOrDefault();
         return(View("~/Views/appdashboard/masterdata/Group/Edit.cshtml", model));
     }
 }
        public MyAppApiResult <bool> AddLike(Guid ArticleId, MemberShip User)
        {
            var result = new MyAppApiResult <bool>();

            try
            {
                using (var db = new MyAppEntities()) {
                    var log = db.MyApp_LookLog.FirstOrDefault(o => o.MemberShipId == User.Id && o.ArticleId == ArticleId);
                    if (log != null)
                    {
                        if (log.IsLike == true)
                        {
                            result.AddError("已喜欢过");
                            return(result);
                        }
                        log.IsLike = true;
                    }
                    else
                    {
                        db.MyApp_LookLog.Add(new MyApp_LookLog()
                        {
                            Id           = Guid.NewGuid(),
                            MemberShipId = User.Id,
                            ArticleId    = ArticleId,
                            IsLike       = true
                        });
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result.AddError(e.Message);
            }
            return(result);
        }