Esempio n. 1
0
        public ResultSvc <InstructorRole> ChangeOrder(InstructorRole instructorRole, bool up)
        {
            var result = new ResultSvc <InstructorRole>(instructorRole);

            try
            {
                if ((instructorRole.Order == 1 && up) || (instructorRole.Order == InstructorRoles.Items.Select(x => x.Order).DefaultIfEmpty(1).Max() && !up))
                {
                    result.Errors.Add("Nelze změnit pořadí! Pořadí je již buď nejmenší nebo největší možné.");
                }
                else
                {
                    var iRole = InstructorRoles.Items.FirstOrDefault(x => x.Order == (up ? instructorRole.Order - 1 : instructorRole.Order + 1));
                    iRole.Order                  = up ? iRole.Order + 1 : iRole.Order - 1;
                    iRole.UserUpdatedId          = Context.HttpContext.User.GetUserId();
                    instructorRole.Order         = up ? instructorRole.Order - 1 : instructorRole.Order + 1;
                    instructorRole.UserUpdatedId = Context.HttpContext.User.GetUserId();
                    InstructorRoles.Update(iRole);
                    InstructorRoles.Update(instructorRole);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
            }
            return(result);
        }
Esempio n. 2
0
        public ResultSvc <InstructorRole> DeleteInstructorRole(InstructorRole instructorRole)
        {
            var result = new ResultSvc <InstructorRole>(instructorRole);

            try
            {
                foreach (var ir in InstructorRoles.Items.Where(x => x.Order > instructorRole.Order))
                {
                    ir.Order--;
                    InstructorRoles.Update(ir);
                }
                instructorRole.UserDeletedId = Context.HttpContext.User.GetUserId();
                InstructorRoles.Delete(instructorRole);
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
            }
            return(result);
        }
Esempio n. 3
0
        public ResultSvc <InstructorRole> CreateInstructorRole(InstructorRole role)
        {
            var result = new ResultSvc <InstructorRole>(role);

            try
            {
                if (!InstructorRoles.Items.Any(x => x.Name == role.Name.Trim()))
                {
                    role.Name          = role.Name?.Trim();
                    role.Order         = InstructorRoles.Items.Select(x => x.Order).DefaultIfEmpty(0).Max() + 1;
                    role.UserCreatedId = Context.HttpContext.User.GetUserId();
                    InstructorRoles.Add(role);
                }
                else
                {
                    result.Errors.Add("Role s tímto názvem již existuje!");
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e.Message);
            }
            return(result);
        }