Пример #1
0
        public BlackListResult EditBlackListRecord(string detail, Guid uid, DateTime endtime, BlackListRecordStatus status)
        {
            var record = database.BlackListRecords.SingleOrDefault(b => b.UID == uid);

            if (uid == null)
            {
                return(BlackListResult.Error(BlackListResult.EditBlackListRecordErrorEnum.EmptyId));
            }
            if (database.BlackListRecords.Where(b => b.UID == uid).Count() == 0)
            {
                return(BlackListResult.Error(BlackListResult.EditBlackListRecordErrorEnum.NoExistingRecord));
            }
            try
            {
                record.Detail  = detail;
                record.EndTime = endtime;
                record.Status  = status;
                Save();
            }
            catch (Exception e)
            {
                return(BlackListResult.Error("出现错误,错误信息:{0}", e.Message));
            }
            return(BlackListResult.Success());
        }
Пример #2
0
        //[AppAuthorize(AppRoleEnum.OrgnizationMember)]//必须被授权为该项目管理员 => 拿到机构管理员的令牌
        public BlackListResult AddBlackListRecord(string Detail, Volunteer volunteer, AppUser adder, DateTime endtime, Organization orgnization = null, Project project = null, BlackListRecordStatus status = BlackListRecordStatus.Enabled)
        {
            if (endtime < System.DateTime.Now)
            {
                return(BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.WrongTime));
            }
            BlackListRecord result = new BlackListRecord
            {
                Detail       = Detail,
                Volunteer    = volunteer,
                Adder        = adder,
                Status       = status,
                Organization = orgnization,
                EndTime      = endtime,
                AddTime      = System.DateTime.Now
            };

            try
            {
                AddBlackListRecord(result);
            }
            catch (Exception e)
            {
                return(BlackListResult.Error("出现错误,错误信息:{0}", e.Message));
            }
            return(BlackListResult.Success());
        }
        public static BlackListResult Success()
        {
            var result = new BlackListResult
            {
                _succeed = true,
                _errors  = {},
            };

            return(result);
        }
        public static BlackListResult Error(int id, params string[] errors)
        {
            if (errors.Count() == 0)
            {
                errors = new string[] { "未提供错误信息。" };
            }
            var result = new BlackListResult
            {
                _succeed     = false,
                _errors      = errors,
                _errorstring = errors.ToString()
            };

            return(result);
        }
Пример #5
0
        public BlackListResult DeleteBlackListRecord(Guid uid)
        {//异常:id为空,找不到id对应的条目
            var record = database.BlackListRecords.Find(uid);

            if (record == null)
            {
                return(BlackListResult.Error(BlackListResult.DeleteBlackListRecordErrorEnum.NonExistingRecord));
            }
            try
            {
                database.BlackListRecords.Remove(record);
                Save();
            }
            catch (Exception e)
            {
                return(BlackListResult.Error("出现错误,错误信息:{0}", e.Message));
            }
            return(BlackListResult.Success());
        }
 public static bool AreSame(BlackListResult a, BlackListResult b)
 {
     if (a == null && b == null)
     {
         return(true);
     }
     if ((a == null && b != null) || (a != null && b == null))
     {
         return(false);
     }
     else if (a.ErrorString == b.ErrorString && a.Succeeded == b.Succeeded)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #7
0
        [AppAuthorize(AppRoleEnum.OrgnizationAdministrator)]//必须是被授权管理某个project的
        public BlackListResult AddBlackListRecord(BlackListRecord brec)
        {
            if (brec == null)
            {
                return(BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.NullRecord));
            }
            IEnumerable <BlackListRecord> tempbrec = null;

            if (brec.Project != null)
            {
                tempbrec = database.BlackListRecords.Where(b => b.Project.Id == brec.Project.Id).ToList();
                // if (database.BlackListRecords.Where(b=>b.Project==brec.Project).Count()!=0)
                if (tempbrec.Count() != 0)
                {
                    foreach (var eptempbrec in tempbrec)
                    {
                        if (AreSame(eptempbrec, brec))
                        {
                            return(BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.ExistingRecord));
                        }
                    }
                    //  return BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.ExistingRecord);
                }
            }
            if (brec.EndTime < System.DateTime.Now)
            {
                return(BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.WrongTime));
            }

            try
            {
                database.BlackListRecords.Add(brec);
                Save();
            }
            catch (Exception e)
            {
                return(BlackListResult.Error("出现错误,错误信息:{0}", e.Message));
            }
            return(BlackListResult.Success());
        }