public async Task<TrainingFormViewModel> GetById(Guid id) { var model = await _dataContext.TrainingForms.AsNoTracking().FirstOrDefaultAsync(x => x.Id == id); var result = AutoMapperUtils.AutoMap<TrainingForm, TrainingFormViewModel>(model); result.TrainingSubjects = await _dataContext.TrainingSubjects.AsNoTracking().Where(x => x.TrainingFormId == id).OrderBy(x => x.Order).ToListAsync(); return result; }
public async Task <Pagination <DepartmentViewModel> > GetAllAsync(DepartmentQueryModel queryModel) { var query = from dept in _dataContext.Departments.Include(x => x.Organization).AsNoTracking() select new DepartmentViewModel { Id = dept.Id, Name = dept.Name, Code = dept.Code, OrganizationId = dept.OrganizationId, Organization = AutoMapperUtils.AutoMap <Organization, OrganizationViewModel>(dept.Organization), LastModifiedOnDate = dept.LastModifiedOnDate }; if (queryModel.ListTextSearch != null && queryModel.ListTextSearch.Count > 0) { foreach (var ts in queryModel.ListTextSearch) { query = query.Where(q => q.Name.Contains(ts) || q.Code.Contains(ts) ); } } if (queryModel.OrganizationId != null && queryModel.OrganizationId != Guid.Empty) { query = query.Where(x => x.OrganizationId == queryModel.OrganizationId); } return(await query.GetPagedAsync(queryModel.CurrentPage.Value, queryModel.PageSize.Value, queryModel.Sort)); }
public async Task <IActionResult> Create(TitleRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = AutoMapperUtils.AutoMap <TitleRequestModel, Title>(requestModel); return await _titleService.SaveAsync(model); })); }
public async Task <IActionResult> Get(Guid id) { return(await ExecuteFunction(async (user) => { var result = await _departmentService.GetById(id); return AutoMapperUtils.AutoMap <Department, DepartmentViewModel>(result); })); }
public async Task<IActionResult> Create(TrainingProgramRequestModel requestModel) { return await ExecuteFunction(async (user) => { var model = AutoMapperUtils.AutoMap<TrainingProgramRequestModel, TrainingProgram, TrainingProgram_UserRequestModel, TrainingProgram_User>(requestModel); return await _trainingProgramService.SaveAsync(model, requestModel.TrainingProgram_Users); }); }
public async Task <IActionResult> Get(Guid id) { return(await ExecuteFunction(async (user) => { var result = await _organizationService.GetById(id); return AutoMapperUtils.AutoMap <Organization, OrganizationViewModel>(result);; })); }
public async Task<IActionResult> Get(Guid id) { return await ExecuteFunction(async (user) => { var result = await _trainingProgramService.GetById(id); return AutoMapperUtils.AutoMap<TrainingProgram, TrainingProgramViewModel>(result); ; }); }
public async Task <IActionResult> Create(OrganizationRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = AutoMapperUtils.AutoMap <OrganizationRequestModel, Organization>(requestModel); return await _organizationService.SaveAsync(model); })); }
public async Task <IActionResult> Create(DepartmentRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = AutoMapperUtils.AutoMap <DepartmentRequestModel, Department>(requestModel); return await _departmentService.SaveAsync(model); })); }
public async Task<IActionResult> Update(Guid id, [FromBody] TrainingProgramRequestModel requestModel) { return await ExecuteFunction(async (user) => { var model = await _trainingProgramService.GetById(id); model = AutoMapperUtils.AutoMap<TrainingProgramRequestModel, TrainingProgram, TrainingProgram_UserRequestModel, TrainingProgram_User>(requestModel, model); return await _trainingProgramService.SaveAsync(model, requestModel.TrainingProgram_Users); }); }
public async Task <AppRoleDetailModel> GetById(Guid Id) { var entity = _dataContext.AppRoles.AsNoTracking().FirstOrDefault(x => x.Id == Id); if (entity == null) { throw new Exception(IRoleService.Message_RoleNotFound); } var result = AutoMapperUtils.AutoMap <Role, AppRoleDetailModel>(entity); result.Permissons = await GetPermisson(Id); return(result); }
public async Task <IActionResult> Update(Guid id, [FromBody] OrganizationRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = await _organizationService.GetById(id); if (model == null) { throw new ArgumentException($"Id {id} không tồn tại"); } model = AutoMapperUtils.AutoMap <OrganizationRequestModel, Organization>(requestModel, model); return await _organizationService.SaveAsync(model); })); }
public async Task <IActionResult> Create([FromForm] UserRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = AutoMapperUtils.AutoMap <UserRequestModel, User>(requestModel); //TODO: FAKE PASSWORD var passwordHasher = new PasswordHasher <User>(); model.Password = passwordHasher.HashPassword(model, Default.Password); var result = await _userService.SaveAsync(model, requestModel.AvatarFile); return AutoMapperUtils.AutoMap <User, UserViewModel>(result); })); }
public async Task <bool> ChangeStatus(Guid id, string status) { var model = await GetById(id); model.Status = status; var trainingProgram_UserRequestModels = new List <TrainingProgram_UserRequestModel>(); foreach (var trp_u in model.TrainingProgram_Users) { var trp_ur = AutoMapperUtils.AutoMap <TrainingProgram_User, TrainingProgram_UserRequestModel>(trp_u); trainingProgram_UserRequestModels.Add(trp_ur); } await SaveAsync(model, trainingProgram_UserRequestModels); return(true); }
public async Task <IActionResult> Update(Guid id, [FromBody] TrainingFormRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var viewModel = await _trainingFormService.GetById(id); var model = AutoMapperUtils.AutoMap <TrainingFormViewModel, TrainingForm>(viewModel); if (model == null) { throw new ArgumentException($"Id {id} không tồn tại"); } model = AutoMapperUtils.AutoMap <TrainingFormRequestModel, TrainingForm>(requestModel, model); return await _trainingFormService.SaveAsync(model, requestModel.TrainingSubjects); })); }
public async Task <IActionResult> Update(Guid id, [FromForm] UserRequestModel requestModel) { return(await ExecuteFunction(async (user) => { var model = await _userService.GetById(id); if (model == null) { throw new ArgumentException($"Id {id} không tồn tại"); } var newModel = AutoMapperUtils.AutoMap <UserRequestModel, User>(requestModel, model); var result = await _userService.SaveAsync(newModel, requestModel.AvatarFile); return AutoMapperUtils.AutoMap <User, UserViewModel>(result); })); }
public async Task <LoginResponseModel> Login(string username, string password) { var user = await _userService.GetByUsername(username); if (user == null) { throw new ArgumentException($"Tên tài khoản hoặc mật khẩu không đúng"); } if (!VerifyPassword(user, password)) { throw new ArgumentException($"Tên tài khoản hoặc mật khẩu không đúng"); } var token = GenerateJwtToken(user); var userVM = AutoMapperUtils.AutoMap <User, UserViewModel>(user); var response = new LoginResponseModel { User = userVM, Token = token }; return(response); }