示例#1
0
        public async Task <ExecutionResponse <object> > DeleteVenue(long Id)
        {
            var venue = _venueQueryRepo.GetAll().FirstOrDefault(x => x.Id == Id && x.CompanyId == CurrentCompanyId);

            if (venue == null)
            {
                return new ExecutionResponse <object>
                       {
                           ResponseCode = ResponseCode.NotFound,
                           Message      = "No record found"
                       }
            }
            ;

            try
            {
                await _venueCommandRepo.DeleteAsync(venue);

                await _venueCommandRepo.SaveChangesAsync();

                return(new ExecutionResponse <object>
                {
                    ResponseCode = ResponseCode.Ok,
                    ResponseData = true
                });
            }
            catch (Exception ex)
            {
                return(new ExecutionResponse <object>
                {
                    ResponseCode = ResponseCode.ServerException,
                    ResponseData = false
                });
            }
        }
示例#2
0
        public async Task <ExecutionResponse <UserModel> > RemoveUserRole(UserRoleModel model)
        {
            var userRole = _userRoleQueryRepo.GetAll().FirstOrDefault(x => x.UserId == model.UserId && x.RoleId == model.RoleId);

            if (userRole != null)
            {
                var role = _roleQueryRepo.GetAll().FirstOrDefault(f => f.Id == model.RoleId);

                if (role == null)
                {
                    return(new ExecutionResponse <UserModel>
                    {
                        ResponseCode = ResponseCode.NotFound,
                        Message = "Role does not exist"
                    });
                }

                var user = _userQueryRepo.GetAll().FirstOrDefault(f => f.Id == model.UserId);
                if (user == null || (CurrentCompanyId != 0 && user.CompanyId != CurrentCompanyId))
                {
                    return(new ExecutionResponse <UserModel>
                    {
                        ResponseCode = ResponseCode.NotFound,
                        Message = "User does not exist"
                    });
                }

                var result = await _ssoService.AddRemoveClaims(new UserClaimModel { Claims = new List <SSOClaim> {
                                                                                        new SSOClaim("role", role.RoleName)
                                                                                    }, UserId = user.SSOUserId }, ClaimAction.Remove);

                if (result.ResponseCode == ResponseCode.Ok)
                {
                    await _userRoleCommandRepo.DeleteAsync(userRole.Id);

                    await _userRoleCommandRepo.SaveChangesAsync();

                    return(await GetUser(model.UserId));
                }
                else
                {
                    return(new ExecutionResponse <UserModel>
                    {
                        ResponseCode = ResponseCode.ServerException,
                        Message = result.Message
                    });
                }
            }
            else
            {
                return(new ExecutionResponse <UserModel>
                {
                    ResponseCode = ResponseCode.ServerException,
                    Message = "User is not attached to specified role"
                });
            }
        }
        public async Task <ExecutionResponse <object> > SetInterviewInterviewers(long[] interviewerIds, long interviewSessionId)
        {
            try
            {
                var interviewSession = _interviewSessionQueryRepo.GetAll().FirstOrDefault(x => x.Id == interviewSessionId && x.CompanyId == CurrentCompanyId);

                if (interviewSession == null)
                {
                    throw new Exception("Interview session does not exist");
                }

                var interviewInterviewers = _interviewSessionInterviewerQueryRepo.GetAll().Where(x => x.InterviewSessionId == interviewSessionId);

                //to add
                foreach (var id in interviewerIds)
                {
                    if (!interviewInterviewers.Select(x => x.Id).ToArray().Contains(id))
                    {
                        await _interviewSessionInterviewerCommandRepo.InsertAsync(new InterviewSessionInterviewer { InterviewSessionId = interviewSessionId, InterviewerId = id, CreateById = _httpContext.GetCurrentSSOUserId() });
                    }
                }

                //to remove
                foreach (var item in interviewInterviewers.ToList())
                {
                    if (!interviewerIds.Contains(item.Id))
                    {
                        await _interviewSessionInterviewerCommandRepo.DeleteAsync(item);
                    }
                }

                await _interviewSessionInterviewerCommandRepo.SaveChangesAsync();

                return(new ExecutionResponse <object>
                {
                    ResponseData = true,
                    ResponseCode = ResponseCode.Ok
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(new ExecutionResponse <object>
                {
                    ResponseData = false,
                    ResponseCode = ResponseCode.ServerException,
                    Message = ex.Message
                });
            }
        }