public async Task <IActionResult> Edit(long id, [Bind("CleaningStaffId,FirstName,MiddleName,LastName,Phone")] CleaningStaff cleaningStaff) { if (id != cleaningStaff.CleaningStaffId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cleaningStaff); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CleaningStaffExists(cleaningStaff.CleaningStaffId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cleaningStaff)); }
public async Task <IActionResult> Create([Bind("CleaningStaffId,FirstName,MiddleName,LastName,Phone")] CleaningStaff cleaningStaff) { if (ModelState.IsValid) { _context.Add(cleaningStaff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cleaningStaff)); }
// 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); }
public async Task <IActionResult> Create(CleaningStaffViewModel model) { if (ModelState.IsValid) { var cleaningStaff = new CleaningStaff { FirstName = model.FirstName, LastName = model.LastName }; if (model.ImageFile != null) { cleaningStaff.ImageUrl = await _imageHelper.UploadImageAsync(model.ImageFile, model.FullName, "CleaningStaff"); } _context.Add(cleaningStaff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
// Getting From database Methods public static List <CleaningStaff> GetCleaningStaffList() { List <CleaningStaff> _cleaners = new List <CleaningStaff>(); try { string queryString1 = "SELECT TOP(1000) [CleaningStaffID] FROM[DB_A5088F_HOTELdb].[dbo].[CleaningStaff]"; using (SqlConnection connection = new SqlConnection( Form1._connectionString)) { SqlCommand command1 = new SqlCommand( queryString1, connection); connection.Open(); SqlDataReader reader1 = command1.ExecuteReader(); try { while (reader1.Read()) { CleaningStaff _cleaner = new CleaningStaff(Convert.ToInt16(reader1[0])); _cleaners.Add(_cleaner); } } finally { reader1.Close(); } connection.Close(); } } catch (Exception e) { } return(_cleaners); }