public async Task <ApiResultVM <string> > Login(LoginVM loginVM) { var userVM = await _userService.GetUser(loginVM.UserName); if (userVM == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("User doesn't exist")); } var userDTO = await dbset.Where(x => x.Id.Equals(userVM.Id)).AsNoTracking().SingleOrDefaultAsync(); var passwordHash = new PasswordHash(); var password = passwordHash.HashPassword(loginVM.Password); if (password == userDTO.PassWord) { if (userDTO.ConfirmEmail == false) { var subject = "Email For Confirm Password"; var tokenemail = GenarateTokenEmail(userDTO.Email); string url = $"{ _configuration["AppUrl"]}/api/emails/email-confirm/?tokenemail={tokenemail}"; var htmlContent = $"Please confirm your email by click here <a href='{url}'> Link</a>"; await _emailService.SendEmail(userDTO.Email, htmlContent, subject); } string token = GenarateToken(userVM); return(new ApiSuccessResultVM <string>(token)); } return(new ApiErrorResultVM <string>("Password is incorrect")); }
public async Task <ApiResultVM <string> > Delete(int id) { var makeVM = await GetById(id); if (makeVM == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Make doesn't exist")); } var checkConstraint = _dbContextDTO.Set <VehicleDTO>().Where(x => x.MakeId.Equals(id)).Where(x => x.isBought == false).AsNoTracking().FirstOrDefault(); if (checkConstraint != null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Can't delete because make is existing in vehicle")); } var makeDTO = _mapper.Map <MakeDTO>(makeVM); makeDTO.isDelete = true; makeDTO.UpdateAt = DateTime.Now; dbset.Update(makeDTO); await _dbContextDTO.SaveChangesAsync(); return(new ApiSuccessResultVM <string>("Delete Success")); }
public async Task <ApiResultVM <string> > Delete(int id) { var VehicleAppraisalVM = await GetById(id); if (VehicleAppraisalVM == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Appraisal value doesn't exist")); } var VehicleAppraisalDTO = _mapper.Map <VehicleAppraisalDTO>(VehicleAppraisalVM); dbset.Remove(VehicleAppraisalDTO); await _dbContextDTO.SaveChangesAsync(); return(new ApiSuccessResultVM <string>("Delete Success")); }
public async Task <ApiResultVM <string> > Delete(int id) { var ConditionVM = await GetById(id); if (ConditionVM == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Condition doesn't exist")); } var ConditionDTO = _mapper.Map <ConditionDTO>(ConditionVM); dbset.Remove(ConditionDTO); await _dbContextDTO.SaveChangesAsync(); return(new ApiSuccessResultVM <string>("Delete Success")); }
public async Task <bool> ConfirmEmail(string token) { var handler = new JwtSecurityTokenHandler(); var readtoken = handler.ReadJwtToken(token); var email = readtoken.Claims.Where(x => x.Type.Equals("Email")).FirstOrDefault().ToString().Split(' ').ElementAt(1); if (email == null) { _dbContextDTO.Dispose(); return(false); } var userDTO = await dbset.Where(x => x.Email.Equals(email)).AsNoTracking().SingleOrDefaultAsync(); userDTO.ConfirmEmail = true; userDTO.UpdateAt = DateTime.Now; dbset.Update(userDTO); await _dbContextDTO.SaveChangesAsync(); return(true); }
public async Task <ApiResultVM <string> > Delete(int id) { var userVM = await GetById(id); if (userVM == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Users doesn't exist")); } var checkConstraint = await _dbContextDTO.Set <VehicleDTO>().Where(x => x.AppUserId.Equals(id)).Where(x => x.isBought == false).AsNoTracking().FirstOrDefaultAsync(); if (checkConstraint != null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Can't delete because users is existing in vehicle")); } var userDTO = await dbset.Where(x => x.Id.Equals(id)).AsNoTracking().SingleOrDefaultAsync(); userDTO.isDelete = true; userDTO.UpdateAt = DateTime.Now; dbset.Update(userDTO); await _dbContextDTO.SaveChangesAsync(); return(new ApiSuccessResultVM <string>("Delete Success")); }
public async Task <ApiResultVM <string> > BuyVehicle(int id) { var vehicleVM = await GetById(id); if (vehicleVM == null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Vehicle doesn't exist")); } var vehicleDTO = _mapper.Map <VehicleDTO>(vehicleVM); vehicleDTO.isBought = true; vehicleDTO.UpdateAt = DateTime.Now; dbset.Update(vehicleDTO); await _dbContextDTO.SaveChangesAsync(); return(new ApiSuccessResultVM <string>("Buy Success")); }