public async Task <IActionResult> RegisterCleaningStaff(CleaningStaffDto cleaningStaffDto) { //if regsitration is not successful //I returns true or false if (!await _staffrepo.RegisterCleaningStaff(cleaningStaffDto)) { return(BadRequest("Registeration not Successful")); } return(Ok("Registred Successfully")); }
// TODO (Oğuzhan) : I couldn't check if there is a same cleaning staff registration in the database because there is not any unique information public async Task <bool> RegisterCleaningStaff(CleaningStaffDto cleaningStaffDto) { bool isExistProvinceAndDistrict = false; //to save provinces and districts at the beginning of the program if (await SaveProvinceAndDistrict()) { //is there any province with given province name in the database var province = await _context.Provinces.FirstOrDefaultAsync(x => x.ProvinceName == cleaningStaffDto.Province); if (province != null) { // is there any district with related provinceId and given district name var district = from n in _context.Districts where n.ProvinceId == province.Id && n.DistrictName == cleaningStaffDto.District select n; if (district.Count() != 0) { isExistProvinceAndDistrict = true; } else { return(false); } } else { return(false); } } else { return(false); } //if there are a province and district with given names if (isExistProvinceAndDistrict == true) { //creating cleaning staff with given informations for the database var Staff = new CleaningStaff(cleaningStaffDto.StaffName, cleaningStaffDto.PhoneNumber, cleaningStaffDto.Province, cleaningStaffDto.District, cleaningStaffDto.Gender, cleaningStaffDto.PersonalDPTApproval, false, DateTime.UtcNow, DateTime.UtcNow); await _context.CleaningStaffs.AddAsync(Staff); } await _context.SaveChangesAsync(); return(true); }