コード例 #1
0
 private int SaveChanges()
 {
     try
     {
         int result = db.SaveChanges();
         return(result);
     }
     catch (Exception ex)
     {
         string message = "error:";
         if (ex.InnerException == null)
         {
             message += ex.Message + ",";
         }
         else if (ex.InnerException.InnerException == null)
         {
             message += ex.InnerException.Message + ",";
         }
         else if (ex.InnerException.InnerException.InnerException == null)
         {
             message += ex.InnerException.InnerException.Message + ",";
         }
         LogHelper.Log.Write(message);
         throw new Exception(message);
     }
 }
コード例 #2
0
        public ActionResult Update(string memberId, string memberName, string isAdmin)
        {
            bool res = false;

            Member member = new Member();

            member = _memberBLL.GetMemberById(Guid.Parse(memberId));

            member.Account = memberName;
            member.IsAdmin = isAdmin == "g" ? 2 : 0;

            using (DFYW_DbContext db = new DFYW_DbContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Set <Member>().Attach(member);
                        db.Entry(member).State = System.Data.Entity.EntityState.Modified;

                        db.SaveChanges();

                        trans.Commit();

                        res = true;
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Log.Write(ex.Message);
                        LogHelper.Log.Write(ex.StackTrace);

                        trans.Rollback();

                        res = false;
                    }
                }
            }

            var obj = new
            {
                res    = res,
                member = new
                {
                    memberId   = memberId,
                    memberName = memberName,
                    isadmin    = isAdmin
                }
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult Update(string followId, string followName)
        {
            Follow follow = new Follow();

            follow            = _followBLL.GetFollow(Guid.Parse(followId));
            follow.FollowItem = followName;

            bool res = false;

            using (DFYW_DbContext db = new DFYW_DbContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Set <Follow>().Attach(follow);
                        db.Entry <Follow>(follow).State = System.Data.Entity.EntityState.Modified;

                        db.SaveChanges();
                        trans.Commit();

                        res = true;
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Log.Write(ex.Message);
                        LogHelper.Log.Write(ex.StackTrace);

                        trans.Rollback();
                        res = false;
                    }
                }
            }

            var obj = new
            {
                res    = res,
                follow = new
                {
                    Id   = followId,
                    Name = followName
                }
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }