예제 #1
0
        public VolunteerResult EditVolunteer(Volunteer a, Volunteer b)
        {
            if (a == null || a.StudentNum == 0)
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.NonExistingVolunteer));
            }
            var v = database.Volunteers.SingleOrDefault(o => o.StudentNum == a.StudentNum);

            v.StudentNum = b.StudentNum;
            v.Name       = b.Name;
            v.Class      = b.Class;
            v.Mobile     = b.Mobile;
            v.Room       = b.Room;
            v.Email      = b.Email;
            Save();
            v = database.Volunteers.SingleOrDefault(o => o.StudentNum == a.StudentNum);
            Volunteer target = v;
            Volunteer edited = v;

            //Volunteer edited = FindVolunteer(b.StudentNum);
            if (edited.Mobile != target.Mobile || edited.Email != target.Email || edited.Room != target.Room)//日志字符串改成“修改联系方式”,现在联系方式:手机 电子邮件 寝室
            {
                bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1}的志愿者基本信息.现学号:{2},姓名:{3}", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditContact, true);
            }
            else
            {
                bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1}的志愿者基本信息.现学号:{2},姓名:{3}", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditVolunteer, true);
            }
            return(VolunteerResult.Success());
        }
예제 #2
0
        public VolunteerResult EditVolunteer(Volunteer a, int num, string name = DEFAULTSTRING, string c = DEFAULTSTRING, string mobile = DEFAULTSTRING, string room = DEFAULTSTRING, string email = DEFAULTSTRING)
        {
            if (num == 0)
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.EmptyId));
            }
            var v = database.Volunteers.SingleOrDefault(o => o.StudentNum == a.StudentNum);

            if (v != null)
            {
                v.StudentNum = num;
                v.Name       = (name == DEFAULTSTRING) ? v.Name : name;
                v.Class      = (c == DEFAULTSTRING) ? v.Class : c;
                v.Mobile     = (mobile == DEFAULTSTRING) ? v.Mobile : mobile;
                v.Room       = (room == DEFAULTSTRING) ? v.Room : room;
                v.Email      = (email == DEFAULTSTRING) ? v.Email : email;
                Save();
                Volunteer target = a;
                Volunteer edited = FindVolunteer(num);
                if (edited.Mobile != target.Mobile || edited.Email != target.Email || edited.Room != target.Room)
                {
                    bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1} (现学号:{2},姓名:{3}) 的志愿者基本信息.", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditContact, true);
                }
                else
                {
                    bool logresult = VolunteerOperationSucceeded(string.Format("修改原学号:{0},姓名:{1} (现学号:{2},姓名:{3}) 的志愿者基本信息.", target.StudentNum, target.Name, edited.StudentNum, edited.Name), target, LogType.EditVolunteer, true);
                }
                return(VolunteerResult.Success());
            }
            else
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.NonExistingVolunteer));
            }
        }
예제 #3
0
        public VolunteerResult AddVolunteer(int num, string name = DEFAULTSTRING, string c = DEFAULTSTRING, string mobile = DEFAULTSTRING, string room = DEFAULTSTRING, string email = DEFAULTSTRING, string skill = DEFAULTSTRING)
        {
            if (num == 0)
            {
                return(VolunteerResult.Error(VolunteerResult.EditVolunteerErrorEnum.EmptyId));
            }
            var v = new Volunteer
            {
                StudentNum       = num,
                Name             = name,
                Class            = c,
                Mobile           = mobile,
                Room             = room,
                Email            = email,
                BlackListRecords = new List <BlackListRecord>(),
                CreditRecords    = new List <CreditRecord>(),
                ProjectCount     = 0,
                Project          = new List <Project>(),
                Skill            = skill,
                Score            = new Volunteer.VScore(),
                TargetedBy       = new List <LogRecord>()
            };

            return(AddVolunteer(v));
        }
예제 #4
0
 public VolunteerResult AddVolunteer(Volunteer v)
 {
     if (v == null)
     {
         return(VolunteerResult.Error(VolunteerResult.AddVolunteerErrorEnum.NullVolunteerObject));
     }
     if (v.StudentNum == 0)
     {
         return(VolunteerResult.Error(VolunteerResult.AddVolunteerErrorEnum.EmptyId));
     }
     if (database.Volunteers.Where(o => o.StudentNum == v.StudentNum).Count() != 0)
     {
         return(VolunteerResult.Error(VolunteerResult.AddVolunteerErrorEnum.SameIdVolunteerExisted, v.StudentNum));
     }
     else
     {
         int stunum = v.StudentNum;
         v.Mobile           = v.Mobile == DEFAULTSTRING ? DEFAULTSTRING : v.Mobile;
         v.Room             = v.Room == DEFAULTSTRING ? DEFAULTSTRING : v.Room;
         v.Name             = v.Name == DEFAULTSTRING ? DEFAULTSTRING : v.Name;
         v.Class            = v.Class == DEFAULTSTRING ? DEFAULTSTRING : v.Class;
         v.Email            = v.Email == DEFAULTSTRING ? DEFAULTSTRING : v.Email; //加入几个列表的初始化.
         v.BlackListRecords = new List <BlackListRecord>();
         v.CreditRecords    = new List <CreditRecord>();
         v.ProjectCount     = 0;
         v.Project          = new List <Project>();
         v.Skill            = v.Skill;
         v.Score            = new Volunteer.VScore();
         v.TargetedBy       = new List <LogRecord>();
         database.Volunteers.Add(v);
         Save();
         Volunteer target    = FindVolunteer(stunum);
         bool      logresult = VolunteerOperationSucceeded(string.Format("已添加学号:[{0}],姓名:[{1}] 的志愿者条目进入数据库.", target.StudentNum, target.Name), target, LogType.EditContact, true);
         return(VolunteerResult.Success());
     }
 }
예제 #5
0
 public VolunteerResult DeleteVolunteer(Volunteer a)
 {
     if (a != null)
     {
         int                    deletedVolunteerStuNum = a.StudentNum;
         string                 deletedVolunteerName   = a.Name;
         var                    volunteer = FindVolunteer(a.StudentNum);
         List <LogRecord>       loglist   = logger.FindLogRecordByTargetVolunteer(volunteer).ToList();
         List <BlackListRecord> blacklist = database.BlackListRecords.Where(b => b.Volunteer.UID == volunteer.UID).ToList();
         //foreach (var log in loglist)
         //{
         //    log.TargetVolunteer = null;
         //}
         //Save();//等待被注释
         database.Volunteers.Remove(volunteer);
         Save();
         bool logresult = VolunteerOperationSucceeded(string.Format("删除学号:{0},姓名:{1}的志愿者条目.", deletedVolunteerStuNum, deletedVolunteerName), null, LogType.DeleteVolunteer);
         return(VolunteerResult.Success());
     }
     else
     {
         return(VolunteerResult.Error(VolunteerResult.DeleteVolunteerErrorEnum.NonExistingVolunteer));
     }
 }