public VacationInfoModel ConvertToVacationInfoModel(VacationInfoModelDTO vimDTO) { VacationInfoModel info = new VacationInfoModel(); try { if (vimDTO != null) { info.Id = vimDTO.Id; info.ConfirmationDocumentAvailable = vimDTO.ConfirmationDocumentAvailable; info.Duration = vimDTO.Duration; info.DurationStr = vimDTO.DurationStr; info.EndDate = vimDTO.EndDate; info.StartDate = vimDTO.StartDate; info.ProcessInstanceId = vimDTO.ProcessInstanceId; info.Approver = (vimDTO.Approver == null) ? null : JsonConvertorExtention.FromJsonString <PersonModel>(vimDTO.Approver); info.Employee = (vimDTO.Employee == null) ? null : JsonConvertorExtention.FromJsonString <PersonModel>(vimDTO.Employee); info.Status = (vimDTO.Status == null) ? null : JsonConvertorExtention.FromJsonString <IconedValueModel>(vimDTO.Status); info.Type = (vimDTO.Type == null) ? null : JsonConvertorExtention.FromJsonString <IconedValueModel>(vimDTO.Type); info.VacationForm = vimDTO.VacationForm; } } catch (Exception ex) { var error = ex.Message; } return(info); }
public VacationInfoModelDTO ConvertToVacationInfoModelDTO(VacationInfoModel vim) { VacationInfoModelDTO info = new VacationInfoModelDTO(); //if (vim.Approver != null) //{ //} if (vim != null) { info.Id = vim.Id; info.ConfirmationDocumentAvailable = vim.ConfirmationDocumentAvailable; info.Duration = vim.Duration; info.DurationStr = vim.DurationStr; info.EndDate = vim.EndDate; info.StartDate = vim.StartDate; info.ProcessInstanceId = vim.ProcessInstanceId; info.Approver = (vim.Approver == null) ? null : JsonConvertorExtention.ToJsonString(vim.Approver); info.Employee = (vim.Employee == null) ? null : JsonConvertorExtention.ToJsonString(vim.Employee); info.Status = (vim.Status == null) ? null : JsonConvertorExtention.ToJsonString(vim.Status); info.Type = (vim.Type == null) ? null : JsonConvertorExtention.ToJsonString(vim.Type); info.VacationForm = (vim.VacationForm == null) ? null : JsonConvertorExtention.FromJsonString <byte[]>(vim.VacationForm.ToJsonString()); } return(info); }
public async Task TestSQLServiceSaveImage() { await InitData(); string path = Path.Combine(Directory.GetCurrentDirectory(), "person.png"); byte[] image = File.ReadAllBytes(path); //get VacationsDataService _vacationsDataService = FactorySingleton.FactoryOffline.Get <VacationsDataService>(); VacationInfoModel _vacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(id); Assert.IsNotNull(_vacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null"); Assert.IsNull(_vacationInfoModel.VacationForm, "Message: vacationInfoModel.VacationForm IS NOT NULL before saving"); Assert.IsNotNull(image, "Error: image byte[] Is Null"); //save _vacationInfoModel.VacationForm = image; await _vacationsDataService.UpdateOrCreateVacationsSql(_vacationInfoModel); VacationInfoModel _updatedVacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(id); Assert.IsNotNull(_updatedVacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null"); Assert.IsNotNull(_updatedVacationInfoModel.VacationForm, "Error: VacationForm Is Null"); byte[] savedimage = JsonConvertorExtention.FromJsonString <byte[]>(_updatedVacationInfoModel.VacationForm.ToJsonString()); Assert.IsNotNull(savedimage, "Error: savedimage byte[] Is Null"); Assert.AreEqual(image[0], savedimage[0], "Message: image byte[0] NOT Equal after save"); Assert.AreEqual(image.Length, savedimage.Length, "Message: image byte.length NOT Equal after save"); //delete _vacationInfoModel.VacationForm = null; await _vacationsDataService.UpdateOrCreateVacationsSql(_vacationInfoModel); _updatedVacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(id); Assert.IsNotNull(_updatedVacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null"); Assert.IsNull(_updatedVacationInfoModel.VacationForm, "Error: VacationForm Is Not Null after delete"); }
public async Task <VacationInfoModel> GetVacationInfo(int id) { VacationInfoModel vacationInfoModel = null; if (IsOnlineMode) { vacationInfoModel = await _vacationManager.GetVacationFromRestByID(this, id); if (vacationInfoModel != null) { await _vacationManager.UpdateOrCreateVacationInSql(vacationInfoModel); } } else { vacationInfoModel = await _vacationManager.GetVacationFromSqlByID(this, id); } if (vacationInfoModel != null && vacationInfoModel.VacationForm != null) { Image = JsonConvertorExtention.FromJsonString <byte[]>(vacationInfoModel.VacationForm.ToJsonString()); } else { Image = null; } return(vacationInfoModel); }
public async Task TestRestServiceSaveImage() { await InitLogin(); string path = Path.Combine(Directory.GetCurrentDirectory(), "person.png"); byte[] image = File.ReadAllBytes(path); Assert.IsNotNull(image, "Message: byte[] image IS NULL"); //Get restService = new RestService(config, "Vacations"); restService.Timeout = timeout; vacationInfoModelsList = await restService.Get <VacationInfoModel>(); Assert.IsNotNull(vacationInfoModelsList, "Message: " + config + "/api/vacations return null"); vacationInfoModel = await restService.Get <VacationInfoModel>(id); Assert.IsNotNull(vacationInfoModel, "Message: " + config + "/api/vacations?id=" + id + " return null"); Assert.IsNull(vacationInfoModel.VacationForm, "Message: vacationInfoModel.VacationForm IS NOT NULL before saving"); //Save vacationInfoModel.VacationForm = image; responce = await restService.Post(vacationInfoModel); //update vacation Assert.AreEqual(responce.StatusCode, System.Net.HttpStatusCode.OK, "Message: " + config + "/api/vacations/post return error"); Assert.AreNotEqual(responce.StatusCode, System.Net.HttpStatusCode.NoContent, "Message: " + config + "/api/vacations/post return NoContent"); Assert.AreNotEqual(responce.StatusCode, System.Net.HttpStatusCode.Forbidden, "Message: " + config + "/api/vacations/post return Forbidden"); Assert.AreNotEqual(responce.StatusCode, System.Net.HttpStatusCode.NotFound, "Message: " + config + "/api/vacations/post return NotFound"); Assert.IsTrue(responce.IsSuccessStatusCode, "Error: Rest.Post Is Not Success Status Code"); VacationInfoModel newvacation = await restService.Get <VacationInfoModel>(id); Assert.IsNotNull(newvacation, "Message: " + config + "/api/vacations?id=" + id + " return null"); Assert.IsNotNull(newvacation.VacationForm, "Message: newvacation.VacationForm IS NULL after saving"); byte[] savedimage = JsonConvertorExtention.FromJsonString <byte[]>(newvacation.VacationForm.ToJsonString()); Assert.IsNotNull(savedimage, "Message: savedimage byte[] IS NULL"); Assert.AreEqual(image[0], savedimage[0], "Message: image byte[0] NOT Equal after save"); Assert.AreEqual(image.Length, savedimage.Length, "Message: image byte.length NOT Equal after save"); //Delete newvacation.VacationForm = null; responce = await restService.Post(newvacation); //delete Image in vacation Assert.AreEqual(responce.StatusCode, System.Net.HttpStatusCode.OK, "Message: " + config + "/api/vacations/post return error"); Assert.AreNotEqual(responce.StatusCode, System.Net.HttpStatusCode.NoContent, "Message: " + config + "/api/vacations/post return NoContent"); Assert.AreNotEqual(responce.StatusCode, System.Net.HttpStatusCode.Forbidden, "Message: " + config + "/api/vacations/post return Forbidden"); Assert.AreNotEqual(responce.StatusCode, System.Net.HttpStatusCode.NotFound, "Message: " + config + "/api/vacations/post return NotFound"); Assert.IsTrue(responce.IsSuccessStatusCode, "Error: Rest.Post Is Not Success Status Code"); VacationInfoModel deletedimagevacation = await restService.Get <VacationInfoModel>(id); Assert.IsNotNull(deletedimagevacation, "Message: " + config + "/api/vacations?id=" + id + " return null"); Assert.IsNull(deletedimagevacation.VacationForm, "Message: newvacation.VacationForm IS NOT NULL after deleting"); }