public Task UpdateLastWorkingDay(SecurityStaff securityStaff) { var taskResult = Task.Run(() => { using (var context = new DbContext()) { var existingRecord = context.SecurityStaffList.FirstOrDefault(p => p.Id == securityStaff.Id); if (existingRecord == null) { throw new Exception("Security Staff detail not found"); } if (existingRecord.JoiningDate > securityStaff.LastWorkingDay) { throw new Exception("Last working day cannot be before date of joining"); } if (securityStaff.Society != null) { securityStaff.SocietyId = securityStaff.Society.Id; securityStaff.Society = null; } existingRecord.LastWorkingDay = securityStaff.LastWorkingDay; context.SaveChanges(); } }); return(taskResult); }
public async Task <IActionResult> Edit(int id, [Bind("id,Fname,Lname,gender,tel,email,position,status,picture")] SecurityStaff securityStaff) { if (id != securityStaff.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(securityStaff); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SecurityStaffExists(securityStaff.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(securityStaff)); }
public Task Update(SecurityStaff securityStaff) { var taskResult = Task.Run(() => { using (var context = new DbContext()) { var existingRecord = context.SecurityStaffList.FirstOrDefault(p => p.Id == securityStaff.Id); if (existingRecord == null) { throw new Exception("Security Staff detail not found"); } var society = context .Societies .FirstOrDefault(s => s.Id == existingRecord.Society.Id); if (society == null) { throw new Exception("Society not found"); } if (securityStaff.JoiningDate < society.DateOfIncorporation) { throw new Exception("Joining date cannot be before date of incorporation of the society"); } if (securityStaff.DateOfBirth.HasValue && securityStaff.JoiningDate < securityStaff.DateOfBirth.Value) { throw new Exception("Joining since date cannot be before Date of Birth"); } if (securityStaff.Society != null) { securityStaff.SocietyId = securityStaff.Society.Id; securityStaff.Society = null; } if (securityStaff.ShiftType != null) { securityStaff.ShiftTypeId = securityStaff.ShiftType.Id; securityStaff.ShiftType = null; } existingRecord.Name = securityStaff.Name; existingRecord.PhoneNo = securityStaff.PhoneNo; existingRecord.AadharCardNo = securityStaff.AadharCardNo; existingRecord.Photo = securityStaff.Photo; existingRecord.DateOfBirth = securityStaff.DateOfBirth; existingRecord.Address = securityStaff.Address; existingRecord.NativeAddress = securityStaff.NativeAddress; existingRecord.JoiningDate = securityStaff.JoiningDate; context.SaveChanges(); } }); return(taskResult); }
public async Task <IActionResult> Create([Bind("id,Fname,Lname,gender,tel,email,position,status,picture")] SecurityStaff securityStaff) { if (ModelState.IsValid) { _context.Add(securityStaff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(securityStaff)); }
public Task <SecurityStaff> Create(SecurityStaff securityStaff) { var taskResult = Task.Run(() => { using (var context = new DbContext()) { var society = context .Societies .FirstOrDefault(s => s.Id == securityStaff.Society.Id); if (society == null) { throw new Exception("Society not found"); } if (securityStaff.JoiningDate < society.DateOfIncorporation) { throw new Exception("Joining date cannot be before date of incorporation of the society"); } if (securityStaff.DateOfBirth.HasValue && securityStaff.JoiningDate < securityStaff.DateOfBirth.Value) { throw new Exception("Joining since date cannot be before Date of Birth"); } if (securityStaff.Society != null) { securityStaff.SocietyId = securityStaff.Society.Id; securityStaff.Society = null; } if (securityStaff.ShiftType != null) { securityStaff.ShiftTypeId = securityStaff.ShiftType.Id; securityStaff.ShiftType = null; } context.SecurityStaffList.Add(securityStaff); context.SaveChanges(); return(securityStaff); } }); return(taskResult); }
public Task UpdateLastWorkingDay(SecurityStaff securityStaff) { return(_securityStaffRepository.UpdateLastWorkingDay(securityStaff)); }
public Task Update(SecurityStaff securityStaff) { return(_securityStaffRepository.Update(securityStaff)); }
public Task <SecurityStaff> Create(SecurityStaff securityStaff) { return(_securityStaffRepository.Create(securityStaff)); }