예제 #1
0
        /// <summary>
        /// 修改|添加功能信息
        /// </summary>
        /// <param name="effect"></param>
        /// <returns></returns>
        public BaseResult UpdateEffect(effect effect)
        {
            BaseResult result = BaseResult.Fail();

            result.code = 0;

            if (effect.id == 0)
            {
                if (dalUsers.RepeatEffectsNameCount(effect.name) != 0)
                {
                    result.code = -2;
                    result.msg  = "名称重名";
                    return(result);
                }

                if (dalUsers.AddEffects(effect) == 0)
                {
                    result.code = -2;
                    result.msg  = "添加失败";
                    return(result);
                }
                return(result);
            }
            if (dalUsers.UpdateEffects(effect) == 0)
            {
                result.code = -2;
                result.msg  = "修改失败";
                return(result);
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 实体查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BaseResult GetEntity(int id)
        {
            BaseResult result = BaseResult.Fail();

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                try
                {
                    users entity = dbContext.Query <users>().Where(p => p.id == id).FirstOrDefault();
                    if (entity == null)
                    {
                        result.code = -1;
                        result.msg  = "查询记录失败";
                    }
                    else
                    {
                        result.code = 0;
                        result.data = entity;
                    }
                }
                catch (Exception ex)
                {
                    //log.Error(ex);
                    result.code = -2;
                    result.msg  = "查询发生错误";
                }
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// 修改|添加用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public BaseResult UpdateUser(users user)
        {
            BaseResult result = BaseResult.Fail();

            int namercount    = dalUsers.RepeatNameUser(user.name);
            int usernamecount = dalUsers.RepeatUsernameUser(user.username);

            if (user.id == 0)
            {
                if (namercount != 0)
                {
                    result.code = -2;
                    result.msg  = "姓名重复";
                    return(result);
                }
                if (usernamecount != 0)
                {
                    result.code = -2;
                    result.msg  = "用户名重复";
                    return(result);
                }
                return(dalUsers.AddUser(user));
            }
            return(dalUsers.UpdateUser(user));
        }
예제 #4
0
        public BaseResult Add(users model)
        {
            BaseResult result          = BaseResult.Fail();
            DateTime   currentDatetime = DateTime.Now;

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                try
                {
                    dbContext.Session.BeginTransaction();
                    dbContext.Insert <users>(() => new users()
                    {
                        name     = model.name,
                        username = model.username,
                        password = model.password,
                        role     = model.role,
                        addtime  = model.addtime,
                        state    = model.state,
                    });
                    dbContext.Session.CommitTransaction();
                    result.code = 0;
                    result.msg  = "添加成功";
                    //记录操作日志
                }
                catch (Exception ex)
                {
                    dbContext.Session.RollbackTransaction();
                    //log.Error(ex);
                    //记录日志 ex.Message
                    result.code = -2;
                    result.msg  = "添加失败,发生错误";
                }
            }
            return(result);
        }
        public async Task <BaseResult <int> > Handle(CreateYearCourseGroupCommand request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string>
                {
                    "Resource not found!"
                }));
            }

            var group = new Group
            {
                GroupName    = request.GroupName,
                GroupNumber  = request.GroupNumber,
                YearCourseId = request.YearCourseId
            };

            await _unitOfWork.GroupRepository.AddAsync(group);

            await _unitOfWork.CommitAsync();

            return(BaseResult <int> .Success(ResultType.Created, group.Id));
        }
        public async Task <BaseResult <int> > Handle(CreateYearCourseSubjectCommand request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string>
                {
                    "Resource not found!"
                }));
            }

            var subject = new Subject
            {
                Name         = request.Name,
                ShortName    = request.ShortName,
                YearCourseId = request.YearCourseId
            };

            await _unitOfWork.SubjectRepository.AddAsync(subject);

            await _unitOfWork.CommitAsync();

            return(BaseResult <int> .Success(ResultType.Created, subject.Id));
        }
예제 #7
0
        /// <summary>
        /// 修改|添加角色信息
        /// </summary>
        /// <param name="relevance"></param>
        /// <returns></returns>
        public BaseResult UpdateRole(relevance relevance)
        {
            BaseResult result = BaseResult.Fail();

            result.code = 0;
            int rolename = dalUsers.RepeatEffectName(relevance.dicvalue);

            if (relevance.id == 0)
            {
                if (rolename != 0)
                {
                    result.code = -2;
                    result.msg  = "角色名重复";
                    return(result);
                }
                dalUsers.AddEffect(relevance.dicvalue);
            }
            if (relevance.NotMapped != null)
            {
                if (dalUsers.UpdateDictionary(relevance.dicvalue, relevance.NotMapped) == 0 && dalUsers.DelRelevance(relevance.NotMapped) == 0)
                {
                    result.code = -2;
                    result.msg  = "出错";
                    return(result);
                }
            }

            string effect = relevance.effectstr;

            if (effect == null || effect == "")
            {
                return(result);
            }
            string[] effectarr = effect.Split(',');
            if (!effect.Contains(","))
            {
                if (effect != "" && effect != null)
                {
                    if (dalUsers.AddRelevance(relevance.dicvalue, Convert.ToInt16(effect)) == 0)
                    {
                        result.code = -2;
                        result.msg  = "添加角色失败";
                        return(result);
                    }
                }

                return(result);
            }

            foreach (var s in effectarr)
            {
                if (dalUsers.AddRelevance(relevance.dicvalue, Convert.ToInt16(s)) == 0)
                {
                    result.code = -2;
                    result.msg  = "添加角色失败";
                    return(result);
                }
            }
            return(result);
        }
        public async Task <BaseResult <Event> > Handle(GetEventDetailsQuery request, CancellationToken cancellationToken)
        {
            //Check if year course exists & if request.eventId belongs to this yearCourse
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            var eventToFetch = await _unitOfWork.EventRepository.GetAsync(request.EventId);

            if (eventToFetch == null || yearCourse == null)
            {
                return(BaseResult <Event> .Fail(ErrorType.NotFound,
                                                new List <string>
                {
                    "Resource not found!"
                }));
            }

            if (!yearCourse.Events.Any(x => x.Id == request.EventId))
            {
                return(BaseResult <Event> .Fail(ErrorType.NotFound,
                                                new List <string>
                {
                    "Requested event doesnt belong to given YearCourse!"
                }));
            }

            return(BaseResult <Event> .Success(ResultType.Ok, eventToFetch));
        }
예제 #9
0
        /// <summary>
        /// 返回所有角色数据
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public BaseResult GetAllRole(int page, int limit)
        {
            BaseResult result = BaseResult.Fail();

            result.code  = 0;
            result.count = dalUsers.GetRoleCount();
            result.data  = dalUsers.GetAllRole(page, limit);
            return(result);
        }
예제 #10
0
        /// <summary>
        /// 返回所有功能数据
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public BaseResult GetAllEffects(int page, int limit)
        {
            BaseResult result = BaseResult.Fail();

            result.code  = 0;
            result.count = dalUsers.GetEffectsCount();
            result.data  = dalUsers.GetAllEffects(page, limit);
            return(result);
        }
예제 #11
0
        /// <summary>
        /// 删除功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BaseResult DelEffects(int id)
        {
            BaseResult result = BaseResult.Fail();

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                dbContext.Delete <effect>(p => p.id == id);
                result.code = 0;
                return(result);
            }
        }
예제 #12
0
        /// <summary>
        /// 批量||单一删除
        /// </summary>
        /// <param name="ids">字符串数组,号分割</param>
        /// <returns></returns>
        public BaseResult Delect(string ids)
        {
            BaseResult result          = BaseResult.Fail();
            DateTime   currentDatetime = DateTime.Now;

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                try
                {
                    dbContext.Session.BeginTransaction();

                    // 批量操作时累计受影响行数
                    int      total   = 0;
                    string[] idArray = ids.Split(',');
                    foreach (string id in idArray)
                    {
                        var temId = Convert.ToInt32(id);

                        var mo = dbContext.Query <users>().Where(s => s.id == temId).FirstOrDefault();
                        if (mo.role == "0")
                        {
                            result.code = -1;
                            result.msg  = "不能删除超级管理员";
                            return(result);
                        }

                        users entity = new users
                        {
                            id = Convert.ToInt32(id)
                        };
                        int effectedRows = dbContext.Delete(entity);
                        if (effectedRows > 0)
                        {
                            total += effectedRows;
                        }
                    }
                    dbContext.Session.CommitTransaction();
                    result.code = 0;
                    result.msg  = string.Format("操作成功,总记录:{0},执行成功:{1}", idArray.Length, total);
                    //记录操作日志
                    // log.Info("删除datadictionary_ids=" + ids + "成功");
                }
                catch (Exception ex)
                {
                    dbContext.Session.RollbackTransaction();
                    // log.Error(ex);
                    //记录日志 ex.Message
                    result.code = -2;
                    result.msg  = "删除失败,发生错误";
                }
            }
            return(result);
        }
예제 #13
0
        public BaseResult <LogonResult> Logon(LogonRequest logon)
        {
            var validator = new LogonRequestValidator();
            var results   = validator.Validate(logon);

            if (results.IsValid)
            {
                return(_gameManager.Execute(logon));
            }
            else
            {
                return(BaseResult <LogonResult> .Fail(errors : results.Errors.Select(e => e.ErrorMessage)));
            }
        }
예제 #14
0
        public BaseResult <StatusResult> Status(StatusRequest status)
        {
            var validator = new StatusRequestValidator();
            var results   = validator.Validate(status);

            if (results.IsValid)
            {
                return(_gameManager.Execute(status));
            }
            else
            {
                return(BaseResult <StatusResult> .Fail(errors : results.Errors.Select(e => e.ErrorMessage)));
            }
        }
예제 #15
0
        public async Task <BaseResult <YearCourse> > Handle(GetYearCourseByIdQuery request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <YearCourse> .Fail(ErrorType.NotFound,
                                                     new List <string>
                {
                    "Resource not found!"
                }));
            }

            return(BaseResult <YearCourse> .Success(ResultType.Ok, yearCourse));
        }
예제 #16
0
        public async Task <BaseResult <List <Group> > > Handle(GetAllYearCourseGroupsQuery request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <List <Group> > .Fail(ErrorType.NotFound, new List <string>
                {
                    "Year course not found!"
                }));
            }

            var groups = await _unitOfWork.GroupRepository.GetAllForYearCourseAsync(request.YearCourseId);

            return(BaseResult <List <Group> > .Success(ResultType.Ok, groups));
        }
        public async Task <BaseResult <List <Event> > > Handle(GetYearCourseEventsQuery request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <List <Event> > .Fail(ErrorType.NotFound,
                                                        new List <string>
                {
                    "Year course does not exist!"
                }));
            }
            var events = await _unitOfWork.EventRepository.GetYearCourseEventAsync(request.YearCourseId, request.Date, request.GroupIds);

            return(BaseResult <List <Event> > .Success(ResultType.Ok, events));
        }
        public async Task <BaseResult <int> > Handle(CreateYearCourseCommand request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(request.CreationApiKey))
            {
                return(BaseResult <int> .Fail(ErrorType.NotAuthenticated,
                                              new List <string>
                {
                    "No password provided!"
                }));
            }

            if (await _unitOfWork.KeyRepository.TryUseKeyAsync(request.CreationApiKey))
            {
                var yearCourse = new YearCourse
                {
                    Password        = request.Password,
                    CurrentSemester = request.CurrentSemester,
                    Course          = request.Course,
                    CourseStartYear = request.CourseStartYear,
                    Faculty         = request.Faculty,
                    University      = request.University,
                    Groups          = request.Groups.Select(g => new Group
                    {
                        GroupName   = g.GroupName,
                        GroupNumber = g.GroupNumber
                    }).ToList(),
                    Subjects = request.Subjects.Select(s => new Subject
                    {
                        Name      = s.Name,
                        ShortName = s.ShortName
                    }).ToList()
                };
                await _unitOfWork.YearCourseRepository.AddAsync(yearCourse);

                await _unitOfWork.CommitAsync();

                return(BaseResult <int> .Success(ResultType.Created, yearCourse.Id));
            }

            await _unitOfWork.RollbackAsync();

            return(BaseResult <int> .Fail(ErrorType.NotAuthorized,
                                          new List <string>
            {
                "Invalid creation api key!"
            }));
        }
예제 #19
0
        /// <summary>
        /// 修改对应账号状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public BaseResult UpdateUserState(int id, int type)
        {
            BaseResult result = BaseResult.Fail();

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                int user = dbContext.Update <users>(p => p.id == id, p => new users()
                {
                    state = type
                });
                result.code = 0;
                if (user == 0)
                {
                    result.code = -1;
                }

                return(result);
            }
        }
예제 #20
0
        public BaseResult Update(users model)
        {
            BaseResult result          = BaseResult.Fail();
            DateTime   currentDatetime = DateTime.Now;

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                try
                {
                    dbContext.Session.BeginTransaction();
                    users entity = dbContext.Query <users>().Where(p => p.id == model.id).FirstOrDefault();
                    if (entity != null)
                    {
                        dbContext.TrackEntity(entity);
                        entity.name     = model.name;
                        entity.username = model.username;
                        entity.password = model.password;
                        entity.role     = model.role;
                        entity.addtime  = model.addtime;
                        entity.state    = model.state;
                        int effectedRows = dbContext.Update(entity);
                        result.code = 0;
                        result.msg  = "修改成功";
                    }
                    else
                    {
                        result.code = -1;
                        result.msg  = "修改失败,记录不存在";
                    }
                    dbContext.Session.CommitTransaction();
                    //记录操作日志
                }
                catch (Exception ex)
                {
                    dbContext.Session.RollbackTransaction();
                    // log.Error(ex);
                    //记录日志 ex.Message
                    result.code = -2;
                    result.msg  = "修改失败,发生错误";
                }
            }
            return(result);
        }
예제 #21
0
        public List <BaseResult <MoveResult> > Move(List <MoveRequest> moves)
        {
            var validator = new MoveRequestValidator();
            var results   = new List <BaseResult <MoveResult> >();

            foreach (var move in moves)
            {
                var result = validator.Validate(move);

                if (result.IsValid)
                {
                    results.Add(_gameManager.Execute(move));
                }
                else
                {
                    results.Add(BaseResult <MoveResult> .Fail(errors: result.Errors.Select(e => e.ErrorMessage)));
                }
            }
            return(results);
        }
예제 #22
0
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BaseResult DelRole(int id)
        {
            BaseResult result = BaseResult.Fail();

            result.code = 0;
            var Single = dalUsers.GetSingleRole(id);

            if (dalUsers.UserHaveRole(Single.value) > 0)
            {
                result.code = -2;
                result.msg  = "存在一个或多个用户使用此角色";
                return(result);
            }
            if (dalUsers.DelRole(id) == 0 && dalUsers.DelRelevance(Single.value) == 0)
            {
                result.code = -2;
                result.msg  = "删除失败";
                return(result);
            }
            return(result);
        }
예제 #23
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public BaseResult Login(string username, string password)
        {
            BaseResult result = BaseResult.Fail();

            using (IDbContext dbContext = DbContextFactory.MySqlCreateDbContext())
            {
                var count = dbContext.Query <users>().Where(p => p.username == username && p.password == password).FirstOrDefault();
                if (count == null)
                {
                    result.code = -1;
                    result.msg  = "用户名或密码错误";
                }
                else
                {
                    result.code = 0;
                    result.data = count;
                    result.msg  = "登陆成功";
                }

                return(result);
            }
        }
예제 #24
0
        /// <summary>
        /// 重置密码“123456”
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BaseResult UpdateBasePassword(int id)
        {
            BaseResult result = BaseResult.Fail();

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                var temp = dbContext.Update <users>(p => p.id == id, p => new users()
                {
                    password = "******"
                });
                if (temp == 0)
                {
                    result.code = -2;
                    result.msg  = "修改失败!";
                    return(result);
                }

                result.code = 0;
                result.msg  = "修改成功!";
                return(result);
            }
        }
예제 #25
0
        /// <summary>
        /// 新增账号
        /// </summary>
        /// <param name="user"></param>
        public BaseResult AddUser(users user)
        {
            BaseResult result = BaseResult.Fail();

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                result.code = 0;
                var temp = (int)dbContext.Insert <users>(() => new users()
                {
                    name     = user.name,
                    username = user.username,
                    password = user.password,
                    role     = user.role
                });
                if (temp == 0)
                {
                    result.code = -1;
                }

                return(result);
            }
        }
예제 #26
0
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public BaseResult UpdateUser(users users)
        {
            BaseResult result = BaseResult.Fail();

            using (IDbContext dbContext = DbContextFactory.CreateDbContext())
            {
                result.code = 0;
                int user = dbContext.Update <users>(p => p.id == users.id, p => new users()
                {
                    name     = users.name,
                    username = users.username,
                    password = users.password,
                    role     = users.role
                });
                if (user == 0)
                {
                    result.code = -1;
                }

                return(result);
            }
        }
        public async Task <BaseResult <int> > Handle(CreateEventCommand request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string>
                {
                    "Resource not found!"
                }));
            }

            var eventToAdd = new Event
            {
                Name         = request.Name,
                Description  = request.Description,
                YearCourseId = request.YearCourseId,
                Date         = request.Date,
                EventTypeId  = request.EventTypeId,
                SubjectId    = request.SubjectId,
                GroupEvents  = new List <GroupEvent>()
            };

            await _unitOfWork.EventRepository.AddAsync(eventToAdd);

            request.GroupIds.ForEach(x =>
            {
                eventToAdd.GroupEvents.Add(new GroupEvent
                {
                    EventId = eventToAdd.Id,
                    GroupId = x
                });
            });

            await _unitOfWork.CommitAsync();

            return(BaseResult <int> .Success(ResultType.Created, eventToAdd.Id));
        }
        public async Task <BaseResult <int> > Handle(CreateEventTypeCommand request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <int> .Fail(ErrorType.NotFound, new List <string>
                {
                    "Year course not found!"
                }));
            }

            var eventType = new EventType()
            {
                Name = request.Name
            };

            await _unitOfWork.EventTypeRepository.AddAsync(eventType);

            await _unitOfWork.CommitAsync();

            return(BaseResult <int> .Success(ResultType.Created, eventType.Id));
        }
예제 #29
0
        public async Task <BaseResult <Subject> > Handle(GetYearCourseSubjectByIdQuery request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsync(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <Subject> .Fail(ErrorType.NotFound, new List <string>
                {
                    "Year course not found!"
                }));
            }

            var subject = await _unitOfWork.SubjectRepository.GetYearCourseSubject(request.YearCourseId, request.SubjectId);

            if (subject == null)
            {
                return(BaseResult <Subject> .Fail(ErrorType.NotFound, new List <string>
                {
                    "Subject not found!"
                }));
            }

            return(BaseResult <Subject> .Success(ResultType.Ok, subject));
        }
        public async Task <BaseResult <List <Event> > > Handle(GetYearCourseEventsForGroupQuery request, CancellationToken cancellationToken)
        {
            var yearCourse = await _unitOfWork.YearCourseRepository.GetAsyncWithGroups(request.YearCourseId);

            if (yearCourse == null)
            {
                return(BaseResult <List <Event> > .Fail(ErrorType.NotFound,
                                                        new List <string>
                {
                    "Year course does not exist!"
                }));
            }
            if (!yearCourse.Groups.Any(x => x.Id == request.GroupId))
            {
                return(BaseResult <List <Event> > .Fail(ErrorType.NotFound,
                                                        new List <string>
                {
                    "Given group does not exist or does not belong to given year course!"
                }));
            }
            var events = await _unitOfWork.EventRepository.GetYearCourseEventsForGroupAsync(request.YearCourseId, request.GroupId, request.Date);

            return(BaseResult <List <Event> > .Success(ResultType.Ok, events));
        }