Example #1
0
        public static void WriteLog(string tableCode, string actionCode, int objectId, int userId, int? approveStageId)
        {
            try
            {
                using (var ctx = new SenLan2Entities(userId))
                {
                    // Add new log
                    var l = new Log();

                    var doc = ctx.Documents.FirstOrDefault(o => o.TableCode == tableCode && !o.IsDeleted);
                    if (doc == null)
                    {
                        throw new FaultException<ServerErr>(new ServerErr(ErrCode.DocumentNotFound),
                            new FaultReason(ErrorMsgManager.GetErrMsg(ErrCode.DocumentNotFound)));
                    }
                    l.DocumentId = doc.Id;

                    var logAction = ctx.LogActions.FirstOrDefault(o => o.Code == actionCode && !o.IsDeleted);
                    if (logAction == null)
                    {
                        throw new FaultException<ServerErr>(new ServerErr(ErrCode.LogActionNotFound),
                            new FaultReason(ErrorMsgManager.GetErrMsg(ErrCode.LogActionNotFound)));
                    }
                    l.LogActionId = logAction.Id;

                    l.LogUserId = userId;

                    if(approveStageId != null && approveStageId > 0)
                    {
                        l.ApprovalStageId = approveStageId;
                    }

                    l.ObjectId = objectId;
                    l.LogTime = DateTime.Now;

                    ctx.Logs.AddObject(l);
                    ctx.SaveChanges();

                    // Add Log Messages
                    var lrs = ctx.LogRegistrations.Where(
                        o => o.DocumentId == doc.Id && o.LogActionId == logAction.Id && !o.IsDeleted).ToList();
                    foreach (var lr in lrs)
                    {
                        var lm = new LogMessage {LogId = l.Id, LogRegistrationId = lr.Id, UserId = lr.UserId, IsRead = false};
                        ctx.LogMessages.AddObject(lm);
                    }

                    ctx.SaveChanges();
                }
            }
            catch (OptimisticConcurrencyException)
            {
                throw new FaultException(ErrCode.OptimisticConcurrencyErr.ToString());
            }
            
        }
Example #2
0
 public string UnBind(string openId)
 {
     using (DBEntity.SenLan2Entities ctx = new DBEntity.SenLan2Entities())
     {
         User u = ctx.Users.Where(o => o.IsDeleted == false && o.WeixinOpenId == openId).FirstOrDefault();
         if (u == null)
             return "解绑定失败,请重试!";
         u.WeixinOpenId = null;
         List<WeixinAlert> alerts = ctx.WeixinAlerts.Where(a => a.UserId == u.Id).ToList();
         foreach (WeixinAlert alert in alerts)
         {
             ctx.DeleteObject(alert);
         }
         ctx.SaveChanges();
         return string.Empty;
     }
 }
Example #3
0
 public string Bind(string name, string password, string openId)
 {
     password = Utility.Misc.Encrypt.Encode(password);
     using (DBEntity.SenLan2Entities ctx = new DBEntity.SenLan2Entities())
     {
         User u = ctx.Users.Where(o => o.IsDeleted == false && o.LoginName == name && o.Password == password).FirstOrDefault();
         if (u == null)
             return "账号或者密码错误,请重试!";
         if(string.IsNullOrEmpty(u.WeixinOpenId) == false)
         {
             return "系统账号" + u.LoginName + "已经绑定微信账号, 请解绑定后再进行新系统账号的绑定!";
         }
         if(ctx.Users.Count(o => o.IsDeleted == false && o.WeixinOpenId == openId) > 0)
         {
             return "该微信账号已经绑定系统账号,请解绑定后再进行新系统账号的绑定!";
         }
         u.WeixinOpenId = openId;
         ctx.SaveChanges();
         return string.Empty;
     }
 }