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 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> > 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")); }
static void Main(string[] args) { var service = new ServiceCollection(); service.AddDbContext <DbContextDTO>(opt => opt.UseSqlServer("Server=DESKTOP-9CB2CPM;Database=VehicleAppraisal;Trusted_Connection=True;")); var serviceProvider = service.BuildServiceProvider(); _dbContextDTO = serviceProvider.GetService <DbContextDTO>(); dbset = _dbContextDTO.Set <VehicleCrawlDataDTO>(); if (dbset.ToList().Where(x => x.CreateAt.Day.Equals(DateTime.Now.Day)).Count() == 0) { foreach (var itemDB in dbset.ToList()) { dbset.Remove(itemDB); } CrawlData(@"https://tinbanxe.vn/audi"); CrawlData(@"https://tinbanxe.vn/vinfast"); CrawlData(@"https://tinbanxe.vn/bmw"); CrawlData(@"https://tinbanxe.vn/ford"); CrawlData(@"https://tinbanxe.vn/honda"); CrawlData(@"https://tinbanxe.vn/lexus"); CrawlData(@"https://tinbanxe.vn/suzuki"); CrawlData(@"https://tinbanxe.vn/toyota"); CrawlData(@"https://tinbanxe.vn/hyundai"); CrawlData(@"https://tinbanxe.vn/mitsubishi"); _dbContextDTO.SaveChangesAsync(); } }
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 <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")); }
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> > Register(RegisterVM registerVM) { var email = await _userService.GetUser(registerVM.Email); var userName = await _userService.GetUser(registerVM.UserName); var fullName = await dbset.Where(x => x.FullName.Equals(registerVM.FullName)).Where(x => x.isDelete == false).AsNoTracking().FirstOrDefaultAsync(); if (userName != null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("UserName is exist")); } if (email != null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("Email is exist")); } if (fullName != null) { _dbContextDTO.Dispose(); return(new ApiErrorResultVM <string>("FullName is exist")); } var passwordHash = new PasswordHash(); var userDTO = _mapper.Map <AppUserDTO>(registerVM); userDTO.PassWord = passwordHash.HashPassword(registerVM.Password); userDTO.AppUserRolesId = 2; userDTO.CreateAt = DateTime.Now; userDTO.UpdateAt = DateTime.Now; await dbset.AddAsync(userDTO); await _dbContextDTO.SaveChangesAsync(); var tokenEmail = GenarateTokenEmail(userDTO.Email); string url = $"{ _configuration["AppUrl"]}/api/emails/email-confirm/?tokenemail={tokenEmail}"; var subject = "Email For Confirm Password"; var htmlContent = $"Please confirm your email by click here <a href='{url}'> Link</a>"; await _emailService.SendEmail(userDTO.Email, htmlContent, subject); return(new ApiSuccessResultVM <string>("Register Success")); }