public IHttpActionResult GetForm(int id) { //string accessType = "CheckIn_ViewAll"; //if (id > 0) // ThrowIfUserHasNoRole(accessType); using (CheckInEntryDataProvider checkInEntryDataProvider = new CheckInEntryDataProvider(Db, ActiveUser, AccessControl, new CheckInQuery(Db))) { var data = checkInEntryDataProvider.Get(id); SaveLog("CheckIn", "GetForm", JsonConvert.SerializeObject(new { primaryKey = id })); return(Ok(new SuccessResponse(data))); } }
public SaveResult <CheckInEntryModel> Save(MobileCheckInDTO checkInDTO, DateTime dateStamp) { checkInDTO.WaktuCheckIn = dateStamp; var checkins = checkInQuery.GetQuery().Where(x => x.SOWAssign_FK == checkInDTO.SOWAssign_FK).ToList(); var uncheckedOuts = checkins.Where(x => x.WaktuCheckOut == null); if (uncheckedOuts != null) { if (uncheckedOuts.Count() > 0) { throw new Kairos.KairosException($"Task ID '{uncheckedOuts.FirstOrDefault().SOWAssign_FK}' is not checked out. Cannot checkin, until previous task checked out."); } } ModelValidationResult validationResult = checkInValidator.Validate(checkInDTO); bool success = false; CheckInEntryModel model = null; if (validationResult.IsValid) { tblT_CheckIn checkIn = AddCheckIn(checkInDTO, dateStamp); Db.SaveChanges(); checkInDTO.CheckIn_PK = checkIn.CheckIn_PK; AddSOWTrackResultIfUserRoleIsDriver(checkInDTO, dateStamp); Db.SaveChanges(); success = true; model = checkInEntryDataProvider.Get(checkIn.CheckIn_PK); } return(new SaveResult <CheckInEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
public SaveResult <CheckInEntryModel> Save(CheckInDTO checkInDTO, DateTime dateStamp) { ModelValidationResult validationResult = checkInValidator.Validate(checkInDTO); bool success = false; CheckInEntryModel model = null; if (validationResult.IsValid) { success = true; Update(checkInDTO, dateStamp); Db.SaveChanges(); model = checkInEntryDataProvider.Get(checkInDTO.CheckIn_PK); } return(new SaveResult <CheckInEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }