public ReturnResult Deleteswift([FromBody] ShitfMaster ShitfMaster) { if (ShitfMaster != null) { var ShitfDelete = _genericService.ShitfMaster.GetAll().Where(x => x.Id == ShitfMaster.Id).FirstOrDefault(); if (ShitfDelete != null) { if (_genericService.ShitfAssignment.SearchFor(x => x.ShitfId == ShitfMaster.Id && x.IsActive == true).Any()) { return(new ReturnResult { Message = "Please first delete all the shifts under this shift assignment", Success = false }); } ShitfDelete.IsActive = false; _genericService.ShitfMaster.Delete(ShitfDelete); _genericService.Commit(); return(new ReturnResult { Message = "Shift delete successful!!", Success = true }); } } return(new ReturnResult { Message = "Failure", Success = false }); }
public async Task <ReturnResult> Saveshift([FromBody] ShitfMaster ShiftDetail) { bool success = false; string Message = ""; var currentUserId = HttpContext.Current.User.Identity.GetUserId(); var user = (await _userService.GetAllAsync()).Where(x => x.Id == HttpContext.Current.User.Identity.GetUserId() && x.IsActive == true).FirstOrDefault(); //if (user != null)// cehck for user //{ //} if (ShiftDetail.Id == 0) { var data = _genericService.ShitfMaster.GetAll().Where(x => x.ShitfName == ShiftDetail.ShitfName.Trim()).ToList(); if (data.Count() == 0) { var result = _genericService.ShitfMaster.GetAll().Where(y => DbFunctions.CreateTime(y.ToTime.Hour, y.ToTime.Minute, y.ToTime.Second) == DbFunctions.CreateTime(ShiftDetail.ToTime.Hour, ShiftDetail.ToTime.Minute, ShiftDetail.ToTime.Second) && DbFunctions.CreateTime(y.FromTime.Hour, y.FromTime.Minute, y.FromTime.Second) == DbFunctions.CreateTime(ShiftDetail.FromTime.Hour, ShiftDetail.FromTime.Minute, ShiftDetail.FromTime.Second)).ToList(); if (ShiftDetail.FromTime != ShiftDetail.ToTime) { if (result.Count() == 0) { ShiftDetail.IsActive = true; ShiftDetail.CreatedBy = currentUserId; ShiftDetail.CreatedOn = DateTime.UtcNow; ShiftDetail.UpdatedBy = currentUserId; ShiftDetail.UpdatedOn = DateTime.UtcNow; ShiftDetail.FromTime = ShiftDetail.FromTime; ShiftDetail.ToTime = ShiftDetail.ToTime; ShiftDetail.OrganizationId = user == null ? null : user.OrganizationId; _genericService.ShitfMaster.Insert(ShiftDetail); Message = "Shift saved successfully!!"; success = true; } else { return(new ReturnResult { Message = "Shift time already assigned to other shift", Success = false }); } } else { return(new ReturnResult { Message = "Shift time invalid", Success = false }); } } else { return(new ReturnResult { Message = "Shift name already assigned to other shift", Success = false }); } } else { var shiftFromDb = _genericService.ShitfMaster.GetById(ShiftDetail.Id); if (shiftFromDb != null) { var data = _genericService.ShitfMaster.GetAll().Where(x => x.Id != ShiftDetail.Id && x.ShitfName == ShiftDetail.ShitfName.Trim()).ToList(); if (data.Count() == 0) { var result = _genericService.ShitfMaster.GetAll().Where(y => y.Id != ShiftDetail.Id && y.ToTime == ShiftDetail.ToTime && y.FromTime == ShiftDetail.FromTime).ToList(); if (result.Count() == 0) { if (ShiftDetail.FromTime != ShiftDetail.ToTime) { if (shiftFromDb != null) { shiftFromDb.ShitfName = ShiftDetail.ShitfName; shiftFromDb.FromTime = ShiftDetail.FromTime; shiftFromDb.ToTime = ShiftDetail.ToTime; shiftFromDb.UpdatedBy = currentUserId; shiftFromDb.UpdatedOn = DateTime.UtcNow; ShiftDetail.IsActive = true; shiftFromDb.CreatedOn = shiftFromDb.CreatedOn; _genericService.ShitfMaster.Update(shiftFromDb); ShiftDetail.OrganizationId = user == null ? null : user.OrganizationId; Message = "Shift update successfully!!"; success = true; } ; } else { return(new ReturnResult { Message = "Shift time invalid", Success = false }); } } else { return(new ReturnResult { Message = "Shift time already assigned to other shift", Success = false }); } } else { return(new ReturnResult { Message = "Shift name already assigned to other shift", Success = false }); } } } _genericService.Commit(); return(new ReturnResult { Message = Message, Success = true }); }