Beispiel #1
0
        public async Task TestRestServiceUpdateVacation()
        {
            await InitLogin();

            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");
            var firstcount = vacationInfoModelsList.Count;

            vacationInfoModel.Type.Value = "TestRestService";
            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");
            vacationInfoModelsList = await restService.Get <VacationInfoModel>();

            Assert.IsNotNull(vacationInfoModelsList, "Message: " + config + "/api/vacations return null");
            var secondcount = vacationInfoModelsList.Count;

            Assert.AreEqual(firstcount, secondcount, "Error: firstcount !=  secondcount after update");
            VacationInfoModel newvacation = await restService.Get <VacationInfoModel>(id);

            Assert.IsNotNull(newvacation, "Message: " + config + "/api/vacations?id=" + id + " return null");
            Assert.AreEqual(vacationInfoModel.Type.Value, newvacation.Type.Value, "Error: not Equal VacationInfoModel after update");
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public async Task TestSQLServiceCreateVacation()
        {
            await InitData();

            VacationsDataService _vacationsDataService = FactorySingleton.FactoryOffline.Get <VacationsDataService>();
            VacationInfoModel    _vacationInfoModel    = await _vacationsDataService.GetVacationByIdFromSql(0);

            Assert.IsNull(_vacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() ZERO ID Is not Null");
            _vacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(id);

            Assert.IsNotNull(_vacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null");
            _vacationInfoModel.Id           = 0;
            _vacationInfoModel.Status.Value = "new";
            await _vacationsDataService.UpdateOrCreateVacationsSql(_vacationInfoModel);

            VacationInfoModel _newVacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(0);

            Assert.IsNotNull(_newVacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() ZERO ID Is Null");
            Assert.AreEqual(_vacationInfoModel.Id, _newVacationInfoModel.Id, "Error: Id not equal");
            Assert.AreEqual(_vacationInfoModel.Status.Value, _newVacationInfoModel.Status.Value, "Error: value not equal");
            await _vacationsDataService.DeleteVacationsInfoInSqlById(0);

            _vacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(0);

            Assert.IsNull(_vacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() ZERO ID Is not Null");
        }
Beispiel #4
0
        public async Task <bool> UpdateOrCreateVacationInfo(VacationInfoModel oldtem)
        {
            if (oldtem == null)
            {
                return(false);
            }
            if (Image != null && Image.Length != 0)
            {
                oldtem.VacationForm = Image;
            }
            else
            {
                oldtem.VacationForm = null;
            }
            bool result = false;

            if (IsOnlineMode)
            {
                result = await _vacationManager.UpdateOrCreateVacationInRest(this, oldtem);

                await _vacationManager.UpdateOrCreateVacationInSql(oldtem);
            }
            else
            {
                await _vacationManager.UpdateOrCreateVacationInSql(oldtem);

                result = true;
            }
            return(await Helper.Complete(result));
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public async Task <VacationInfoModel> GetVacationByIdFromSql(int id)
        {
            string            result   = String.Empty;
            VacationInfoModel vacation = null;

            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
                if (sqliteService != null)
                {
                    var vacationInfoModelDTO = await sqliteService.Get <VacationInfoModelDTO>(id.ToString());

                    if (vacationInfoModelDTO != null)
                    {
                        vacation = _converter.ConvertToVacationInfoModel(vacationInfoModelDTO);
                    }
                }
            }
            catch (AggregateException e)
            {
                result   = e.InnerExceptions[0].Data["message"].ToString();
                vacation = null;
            }
            catch (Exception e)
            {
                result   = e.Message;
                vacation = null;
            }
            return(await Helper.Complete(vacation));
        }
Beispiel #7
0
        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");
        }
Beispiel #8
0
        public async Task IntegrationSaveImage()
        {
            VacationsViewModel vacationsViewModel = (onlineMode) ? FactorySingleton.Factory.Get <VacationsViewModel>() : FactorySingleton.FactoryOffline.Get <VacationsViewModel>();
            List <VTSModel>    vtsList            = await vacationsViewModel.GetVTSList();

            Assert.IsNotNull(vtsList, "Message: GetVTSList error");
            VacationInfoModel vacationInfo = await vacationsViewModel.GetVacationInfo(vtsList[0].Id);

            Assert.IsNotNull(vacationInfo, "Message: GetVacationInfo error");
            string path = Path.Combine(Directory.GetCurrentDirectory(), "person.png");

            Assert.IsTrue(File.Exists(path), "Message: test image file not found in TEST project");
            byte[] imageByte = File.ReadAllBytes(path);
            Assert.IsNotNull(imageByte, "Message: File.ReadAllBytes file in byte is NULL");
            vacationsViewModel.Image = imageByte;
            Assert.IsNotNull(vacationsViewModel.Image, "Message: test image byte[] is Null");
            Assert.IsTrue((await vacationsViewModel.UpdateOrCreateVacationInfo(vacationInfo)), "Message: error UpdateOrCreateVacationInfo");
            vacationsViewModel.Image = null;
            VacationInfoModel vacationInfoUpdated = await vacationsViewModel.GetVacationInfo(vtsList[0].Id);

            Assert.IsNotNull(vacationsViewModel.Image, "Message:vacationsViewModel.Image after GetVacationInfo Is Null");
            Assert.AreEqual(vacationsViewModel.Image.Length, imageByte.Length, "Message: Not equal Length Image byte[] from viewmodel and real image");
            Assert.AreEqual(vacationsViewModel.Image[0], imageByte[0], "Message: Not equal first byte Image byte[] from viewmodel and real image");

            vacationsViewModel.Image = null;//delete Image
            Assert.IsNull(vacationsViewModel.Image, "Message: test image byte[] is not Null");
            Assert.IsTrue((await vacationsViewModel.UpdateOrCreateVacationInfo(vacationInfo)), "Message: error UpdateOrCreateVacationInfo");
            vacationInfoUpdated = await vacationsViewModel.GetVacationInfo(vtsList[0].Id);

            Assert.IsNull(vacationsViewModel.Image, "Message:vacationsViewModel.Image after GetVacationInfo Is not Null");
        }
Beispiel #9
0
        private async Task  FillData(View view)
        {
            _vacationsViewModel = FactorySingleton.Factory.Get <VacationsViewModel>();
            _vacationInfo       = await _vacationsViewModel.CreateDraftVacationInfo();

            view.FindViewById <TextView>(Resource.Id.ItemEmployee).Text               = _vacationInfo.Employee.FullName;
            view.FindViewById <TextView>(Resource.Id.ItemApprover).Text               = _vacationInfo.Approver.FullName;
            view.FindViewById <TextView>(Resource.Id.ItemDuration).Text               = String.Format("{0} {1}", ConverterHelper.CalculateDuration(DateTime.Now.Date, DateTime.Now.Date), _vacationsViewModel.Localaizer.Localize("days"));
            view.FindViewById <TextView>(Resource.Id.ItemStatus).Text                 = _vacationInfo.Status.Value;
            view.FindViewById <TextView>(Resource.Id.ItemEmployee).Typeface           = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.ItemType).Typeface               = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.ItemApprover).Typeface           = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <Button>(Resource.Id.ItemStartDateBtn).Typeface         = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <Button>(Resource.Id.ItemEndDateBtn).Typeface           = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.ItemDuration).Typeface           = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.ItemStatus).Typeface             = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.ItemError).Typeface              = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <Button>(Resource.Id.ItemPickImageFromGallery).Typeface = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <Button>(Resource.Id.ItemPickImageFromCamera).Typeface  = FontLoader.GetFontNormal((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.LabelEmployee).Typeface          = FontLoader.GetFontBold((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.LabelType).Typeface              = FontLoader.GetFontBold((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.LabelApprover).Typeface          = FontLoader.GetFontBold((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.LabelDuration).Typeface          = FontLoader.GetFontBold((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.LabelStatus).Typeface            = FontLoader.GetFontBold((Activity)_container.Context);
            view.FindViewById <TextView>(Resource.Id.LabelAttachment).Typeface        = FontLoader.GetFontBold((Activity)_container.Context);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        public async Task IntegrationCreateVacation()
        {
            VacationsViewModel vacationsViewModel = (onlineMode) ? FactorySingleton.Factory.Get <VacationsViewModel>() : FactorySingleton.FactoryOffline.Get <VacationsViewModel>();
            List <VTSModel>    vtsList            = await vacationsViewModel.GetVTSList();

            Assert.IsNotNull(vtsList, "Message: GetVTSList error");

            VacationInfoModel vacationInfo = await vacationsViewModel.GetVacationInfo(vtsList[0].Id);

            Assert.IsNotNull(vacationInfo, "Message: GetVacationInfo error");

            var oldcount = vtsList.Count;
            VacationInfoModel vacationInfoNew = await vacationsViewModel.CreateDraftVacationInfo();

            Assert.IsNotNull(vacationInfoNew, "Message: CreateDraftVacationInfo error");
            vacationInfoNew.Type.Value = "TESTING";
            await vacationsViewModel.UpdateDraftVacationInfo(vacationInfoNew);

            if (onlineMode)
            {
                Assert.IsTrue((await vacationsViewModel.SendDraftVacationInfo()), "Message: error SendDraftVacationInfo");
                vtsList = await vacationsViewModel.GetVTSList();

                Assert.AreEqual(vtsList.Count, (oldcount + 1), "Message: error after Create newcount != oldcount + 1");
                VacationInfoModel vacationInfoSaved = await vacationsViewModel.GetVacationInfo(vtsList[vtsList.Count - 1].Id);

                Assert.IsNotNull(vacationInfoSaved, "Message: GetVacationInfo2 error");
                Assert.AreEqual(vacationInfoNew.Type.Value, vacationInfoSaved.Type.Value, "Message: error vacationInfoNew not Equals Type.Value vacationInfoSaved");
            }
        }
Beispiel #12
0
        public async Task InitData()
        {
            await FactorySingleton.FactoryOffline.Get <LoginDataService>().SaveLoginModelToSQLite("vasya", "secret");

            List <VacationInfoModel> _vacationList = new VacationInfoMockModel().Vacations;
            List <VTSModel>          _vtsModelList = new List <VTSModel>();
            ModelConverter           converter     = new ModelConverter(FactorySingleton.FactoryOffline.Get <LocalizeService>());

            if (_vacationList != null)
            {
                foreach (VacationInfoModel info in _vacationList)
                {
                    _vtsModelList.Add(converter.ConvertToVTSModel(info));
                }
            }
            if (_vtsModelList != null && _vtsModelList.Count != 0)
            {
                await FactorySingleton.FactoryOffline.Get <VacationsDataService>().SaveVacationsToSql(_vtsModelList);
            }

            VacationInfoModel mockVacationInfoModel = new VacationInfoModel();

            mockVacationInfoModel.Id = id;
            mockVacationInfoModel.ConfirmationDocumentAvailable = true;
            mockVacationInfoModel.Duration          = 28800000;
            mockVacationInfoModel.DurationStr       = string.Empty;
            mockVacationInfoModel.EndDate           = (long)(DateTime.Now.Date - new DateTime(1970, 1, 1)).TotalMilliseconds;
            mockVacationInfoModel.StartDate         = (long)(DateTime.Now.Date - new DateTime(1970, 1, 1)).TotalMilliseconds;
            mockVacationInfoModel.ProcessInstanceId = string.Empty;
            mockVacationInfoModel.Approver          = new PersonModel()
            {
                Email    = "*****@*****.**",
                FullName = "Dasha Pupkina",
                Id       = "12837487532",
                Region   = ""
            };
            mockVacationInfoModel.Employee = new PersonModel()
            {
                Email    = "*****@*****.**",
                FullName = "Vasil Pupkin",
                Id       = "123438723984",
                Region   = ""
            };
            mockVacationInfoModel.Status = new IconedValueModel()
            {
                Icon  = "red-circle",
                Key   = "waiting",
                Value = VacationStatus.Draft.ToString()
            };
            mockVacationInfoModel.Type = new IconedValueModel()
            {
                Icon  = "",
                Key   = "VAC",
                Value = "Regular (VAC)"
            };
            mockVacationInfoModel.VacationForm = null;
            await FactorySingleton.FactoryOffline.Get <VacationsDataService>().UpdateOrCreateVacationsSql(mockVacationInfoModel);

            await FactorySingleton.FactoryOffline.Get <VacationsDataService>().DeleteVacationsInfoInSqlById(0);//delete temp item for create draft
        }
Beispiel #13
0
        public async Task <bool> SendDraftVacationInfo()
        {
            VacationInfoModel vacationInfoModel = await _vacationManager.GetVacationFromSqlByID(this, 0);

            if (vacationInfoModel == null)
            {
                return(false);
            }
            if (Image != null && Image.Length != 0)
            {
                vacationInfoModel.VacationForm = Image;
            }
            bool result = false;

            if (IsOnlineMode)
            {
                result = await _vacationManager.UpdateOrCreateVacationInRest(this, vacationInfoModel);

                if (result)
                {
                    await _vacationManager.DeleteVacationsInfoInSqlById(0);
                }
            }
            else
            {
                result = false;
            }
            return(await Helper.Complete(result));
        }
Beispiel #14
0
        public VacationInfoModel ConvertToVacationInfoModel(VTSModel vtsModel)
        {
            VacationInfoModel info = new VacationInfoModel();

            info.Id     = vtsModel.Id;
            info.Status = VacationInfoMockModel.VAC;
            return(info);
        }
Beispiel #15
0
        public async Task <VacationInfoModel> CreateDraftVacationInfo()
        {
            VacationInfoModel vacInfo = await _vacationManager.GetVacationFromSqlByID(this, 0);

            if (vacInfo == null)
            {
                vacInfo    = new VacationInfoModel();
                vacInfo.Id = 0;
                vacInfo.ConfirmationDocumentAvailable = true;
                vacInfo.Duration          = 28800000;
                vacInfo.DurationStr       = string.Empty;
                vacInfo.EndDate           = (long)(DateTime.Now.Date - new DateTime(1970, 1, 1)).TotalMilliseconds;
                vacInfo.StartDate         = (long)(DateTime.Now.Date - new DateTime(1970, 1, 1)).TotalMilliseconds;
                vacInfo.ProcessInstanceId = string.Empty;
                vacInfo.Approver          = new PersonModel()
                {
                    Email    = "*****@*****.**",
                    FullName = "Dasha Pupkina",
                    Id       = "12837487532",
                    Region   = ""
                };
                vacInfo.Employee = new PersonModel()
                {
                    Email    = "*****@*****.**",
                    FullName = "Vasil Pupkin",
                    Id       = "123438723984",
                    Region   = ""
                };
                vacInfo.Status = new IconedValueModel()
                {
                    Icon  = "red-circle",
                    Key   = "waiting",
                    Value = VacationStatus.Draft.ToString()
                };
                vacInfo.Type = new IconedValueModel()
                {
                    Icon  = "",
                    Key   = "VAC",
                    Value = "Regular (VAC)"
                };
                vacInfo.VacationForm = null;
                await _vacationManager.UpdateOrCreateVacationInSql(vacInfo);
            }
            else
            {
                vacInfo.Status = new IconedValueModel()
                {
                    Icon  = "red-circle",
                    Key   = "waiting",
                    Value = VacationStatus.Draft.ToString()
                };
            }
            return(await Helper.Complete(vacInfo));
        }
Beispiel #16
0
        public async Task TestSQLServiceGetVacationById()
        {
            await InitData();

            VacationsDataService _vacationsDataService = FactorySingleton.FactoryOffline.Get <VacationsDataService>();
            VacationInfoModel    _vacationInfoModel    = await _vacationsDataService.GetVacationByIdFromSql(id);

            Assert.IsNotNull(_vacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null");
            Assert.AreEqual(_vacationInfoModel.Id, id, "Error: ID != from request");
            _vacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(0);

            Assert.IsNull(_vacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() get infomodel by zero ID is not Null");
        }
Beispiel #17
0
        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");
        }
Beispiel #18
0
        public async Task IntegrationUpdateVacation()
        {
            VacationsViewModel vacationsViewModel = (onlineMode) ? FactorySingleton.Factory.Get <VacationsViewModel>() : FactorySingleton.FactoryOffline.Get <VacationsViewModel>();
            List <VTSModel>    vtsList            = await vacationsViewModel.GetVTSList();

            Assert.IsNotNull(vtsList, "Message: GetVTSList error");
            var oldcount = vtsList.Count;
            VacationInfoModel vacationInfo = await vacationsViewModel.GetVacationInfo(vtsList[0].Id);

            Assert.IsNotNull(vacationInfo, "Message: GetVacationInfo error");
            vacationInfo.Type.Value = "updating";
            Assert.IsTrue((await vacationsViewModel.UpdateOrCreateVacationInfo(vacationInfo)), "Message: error UpdateOrCreateVacationInfo");
            Assert.AreEqual((await vacationsViewModel.GetVTSList()).Count, oldcount, "Message: error after Update newcount != oldcount");
            VacationInfoModel vacationInfoUpdated = await vacationsViewModel.GetVacationInfo(vtsList[0].Id);

            Assert.AreEqual(vacationInfoUpdated.Type.Value, vacationInfo.Type.Value, "Message: error vacationInfoNew not Equals Type.Value vacationInfoSaved");
        }
Beispiel #19
0
        public VTSModel ConvertToVTSModel(VacationInfoModel vacationInfo)
        {
            VTSModel vtsModel = new VTSModel();

            vtsModel.Id = vacationInfo.Id;
            if (vacationInfo.Type.Value != null)
            {
                vtsModel.VacationType = vacationInfo.Type.Value;
            }
            vtsModel.StartDate = vacationInfo.StartDate;
            vtsModel.EndDate   = vacationInfo.EndDate;
            var startDate  = LocalizeMonth((new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddMilliseconds(vacationInfo.StartDate).ToLocalTime().ToString("MMM dd, yyyy"));
            var endDate    = LocalizeMonth((new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddMilliseconds(vacationInfo.EndDate).ToLocalTime().ToString("MMM dd, yyyy"));
            var _startDate = ConverterHelper.ConvertMillisecToDateTime(vacationInfo.StartDate);
            var _endDate   = ConverterHelper.ConvertMillisecToDateTime(vacationInfo.EndDate);
            var dayCount   = ConverterHelper.CalculateDuration(_startDate, _endDate);
            var days       = string.Empty;

            if (dayCount == 1)
            {
                days = _localizer.Localize("day");
            }
            else
            {
                if (dayCount > 1 && dayCount < 5)
                {
                    days = _localizer.Localize("day24");
                }
                else
                {
                    days = _localizer.Localize("days");
                }
            }
            vtsModel.Date = startDate + " - " + endDate + " (" + dayCount + " " + days + ")";
            if (vacationInfo.Status != null)
            {
                vtsModel.Status = vacationInfo.Status.Value;
            }

            if (vacationInfo.Type.Value != null)
            {
                vtsModel.VacationType = vacationInfo.Type.Value;
            }
            return(vtsModel);
        }
Beispiel #20
0
        public async Task TestSQLServiceUpdateVacationById()
        {
            await InitData();

            VacationsDataService _vacationsDataService = FactorySingleton.FactoryOffline.Get <VacationsDataService>();
            VacationInfoModel    _vacationInfoModel    = await _vacationsDataService.GetVacationByIdFromSql(id);

            Assert.IsNotNull(_vacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null");
            _vacationInfoModel.Status.Value = "sqltest";
            VacationInfoModel _notUpdatedVacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(id);

            Assert.IsNotNull(_notUpdatedVacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null");
            Assert.AreNotEqual(_notUpdatedVacationInfoModel.Status.Value, _vacationInfoModel.Status.Value, "Error: _notUpdatedVacationInfoModel == _vacationInfoModel (changed field)");
            await _vacationsDataService.UpdateOrCreateVacationsSql(_vacationInfoModel);

            VacationInfoModel _updatedVacationInfoModel = await _vacationsDataService.GetVacationByIdFromSql(id);

            Assert.IsNotNull(_updatedVacationInfoModel, "Error: vacationsDataService.GetVacationListFromSQL() Is Null");
            Assert.AreEqual(_vacationInfoModel.Status.Value, _updatedVacationInfoModel.Status.Value, "Error: _vacationInfoModel != _updatedVacationInfoModel");
        }
Beispiel #21
0
        public async Task UpdateOrCreateVacationsSql(VacationInfoModel vacation)
        {
            if (vacation == null)
            {
                return;
            }
            try
            {
                if (sqliteService == null)
                {
                    sqliteService = new SQLiteService(_sqlitePlatform, await _fileSystemService.GetPath(_configuration.SqlDatabaseName));
                }
            }
            catch (Exception exp)
            {
                sqliteService = null;
            }
            if (sqliteService != null)
            {
                try
                {
                    var oldvacation = await sqliteService.Get <VacationInfoModelDTO>(vacation.Id.ToString());

                    if (oldvacation != null)
                    {
                        await sqliteService.Update(_converter.ConvertToVacationInfoModelDTO(vacation));
                    }
                    else
                    {
                        await sqliteService.Insert(_converter.ConvertToVacationInfoModelDTO(vacation));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Beispiel #22
0
        public async Task <VacationUpdateResponce> UpdateOrCreateVacationsRest(VacationInfoModel vacation)
        {
            string result       = String.Empty;
            bool   loginSuccess = false;

            try
            {
                RestService restService = new RestService(_configuration.RestServerUrl, "Vacations");
                restService.Timeout = _configuration.ServerTimeOut;
                var request = await restService.Post(vacation);

                loginSuccess = request.IsSuccessStatusCode;
                if (request.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    result = "notFound";
                }
                if (request.StatusCode == System.Net.HttpStatusCode.Forbidden)
                {
                    result = "IncorrectLoginOrPassword";
                }
                if (request.StatusCode == System.Net.HttpStatusCode.NoContent || request.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    result = String.Empty;
                }
            }
            catch (AggregateException e)
            {
                result       = e.InnerExceptions[0].Data["message"].ToString();
                loginSuccess = false;
            }
            catch (Exception e)
            {
                result       = e.Message;
                loginSuccess = false;
            }

            return(await Helper.Complete(new VacationUpdateResponce(vacation.Id, loginSuccess, result)));
        }
Beispiel #23
0
        public async Task <VacationInfoModel> GetVacationByIdFromRest(int id)
        {
            string            result       = String.Empty;
            bool              loginSuccess = false;
            VacationInfoModel vacation     = null;

            try
            {
                RestService restService = new RestService(_configuration.RestServerUrl, "Vacations");
                restService.Timeout = _configuration.ServerTimeOut;
                vacation            = await restService.Get <VacationInfoModel>(id);
            }
            catch (AggregateException e)
            {
                result   = e.InnerExceptions[0].Data["message"].ToString();
                vacation = null;
            }
            catch (Exception e)
            {
                result   = e.Message;
                vacation = null;
            }
            return(await Helper.Complete(vacation));
        }
Beispiel #24
0
 public void Add(VacationInfoModel info)
 {
     info.Id = Vacations.Any() ? Vacations.Max(x => x.Id) + 1 : 1;
     info.ProcessInstanceId = "10" + info.Id;
     Vacations.Add(info);
 }
Beispiel #25
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.ActionBar);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetHomeButtonEnabled(true);
            SetContentView(Resource.Layout.CreateScreen);
            _vacationsViewModel = FactorySingleton.Factory.Get <VacationsViewModel>();
            if (_vacationsViewModel.IsOnlineMode)
            {
                ActionBar.SetTitle(Resource.String.newRequest);
            }
            else
            {
                ActionBar.SetTitle(Resource.String.newRequestOffline);
            }
            _vacationInfo = await _vacationsViewModel.CreateDraftVacationInfo();

            if (_vacationInfo == null)
            {
                Intent myIntent = new Intent(this, typeof(MainScreenActivity));
                SetResult(Result.Canceled, myIntent);
                Exit();
                return;
            }
            if (Intent.Extras != null)
            {
                _typevacation = Intent.Extras.GetInt("typevacation");
                switch (_typevacation)
                {
                case VACATION_REQUEST:
                {
                    _vacationInfo.Type.Key   = "VAC";
                    _vacationInfo.Type.Value = "Regular (VAC)";
                    break;
                }

                case SICK_REQUEST:
                {
                    _vacationInfo.Type.Key   = "ILL";
                    _vacationInfo.Type.Value = "Illness (ILL)";
                    break;
                }

                case OVERTIME_REQUEST:
                {
                    _vacationInfo.Type.Key   = "OVT";
                    _vacationInfo.Type.Value = "Overtime (OVT)";
                    break;
                }

                case LIVEWOP_REQUEST:
                {
                    _vacationInfo.Type.Key   = "POV";
                    _vacationInfo.Type.Value = "Without pay (POV)";
                    break;
                }

                case EXCEPTIONAL_REQUEST:
                {
                    _vacationInfo.Type.Key   = "EXV";
                    _vacationInfo.Type.Value = "EXCEPTIONAL (EXV)";
                    break;
                }
                }
                await _vacationsViewModel.UpdateDraftVacationInfo(_vacationInfo);
            }
            else
            {
                Finish();
            }
            FragmentTransaction transaction = FragmentManager.BeginTransaction();

            _fragment = new VacationTabsFragment();
            transaction.Replace(Resource.Id.sample_content_fragment, _fragment);
            transaction.Commit();
        }
Beispiel #26
0
        protected async void InintAndLocalizeControl()
        {
            if (_vacationsViewModel == null)
            {
                GoToLoginScreen();
                return;
            }
            _vacationInfo = await _vacationsViewModel.GetVacationInfo(ID);

            if (_vacationInfo == null && _vacationsViewModel.State == UserState.Unauthorized)
            {
                GoToLoginScreen();
                return;
            }
            _vacationError.Text = string.Empty;
            _employee.Text      = _vacationInfo.Employee.FullName;
            _vacationType.Text  = _vacationInfo.Type.Value;
            _approver.Text      = _vacationInfo.Approver.FullName;
            _startDate          = ConverterHelper.ConvertMillisecToDateTime(_vacationInfo.StartDate).Date;
            //_vacationStartDateBtn.MinimumDate = (NSDate)DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
            _vacationStartDateBtn.SetDate((NSDate)_startDate.Date.AddHours(2), true);
            _endDate = ConverterHelper.ConvertMillisecToDateTime(_vacationInfo.EndDate).Date;
            //_vacationEndDateBtn.MinimumDate = (NSDate)DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
            _vacationEndDateBtn.SetDate((NSDate)_endDate.Date.AddHours(2), true);
            _duration.Text = string.Format("{0} {1}", ConverterHelper.CalculateDuration(_startDate, _endDate), Localize("days"));
            if (_vacationInfo.Status.Value.Equals(VacationStatus.Approved.ToString()))
            {
                _approved = true;
                _vacationStatus.TextColor                    = UIColor.Green;
                _vacationStartDateBtn.Enabled                =
                    _vacationPickImageFromGallery.Enabled    =
                        _vacationPickImageFromCamera.Enabled =
                            _vacationEndDateBtn.Enabled      = false;
            }
            else
            {
                _approved = false;
                if (_vacationInfo.Status.Value.Equals(VacationStatus.Rejected.ToString()))
                {
                    _vacationStatus.TextColor = UIColor.Red;
                }
                else
                {
                    if (_vacationInfo.Status.Value.Equals(VacationStatus.Closed.ToString()))
                    {
                        _vacationStatus.TextColor = UIColor.Black;
                    }
                    else
                    {
                        _vacationStatus.TextColor = UIColor.Black;
                    }
                }
            }
            if (_vacationsViewModel.Image != null)
            {
                UIImage img = ImageConverter.ToImage(_vacationsViewModel.Image);
                if (img != null)
                {
                    _vacationImage.Image = img;
                }
            }
            _vacationStatus.Text = _vacationInfo.Status.Value;
            var translate = Localize(_vacationInfo.Status.Value);

            if (!translate.Equals("N/A"))
            {
                _vacationStatus.Text = translate;
            }
            _labelEmployee.Text       = _vacationsViewModel.Employee;
            _labelVacationType.Text   = _vacationsViewModel.VacationType;
            _labelApprover.Text       = _vacationsViewModel.Approver;
            _labelDuration.Text       = _vacationsViewModel.Duration;
            _labelVacationStatus.Text = _vacationsViewModel.Status;
            _labelAttachments.Text    = _vacationsViewModel.Attachments;
            _vacationPickImageFromGallery.SetTitle(_vacationsViewModel.Gallery, UIControlState.Normal);
            _vacationPickImageFromCamera.SetTitle(_vacationsViewModel.Camera, UIControlState.Normal);
        }
Beispiel #27
0
        public async Task <bool> UpdateOrCreateVacationInRest(VacationsViewModel viewModel, VacationInfoModel vacation)
        {
            VacationUpdateResponce responce = null;

            try
            {
                responce = await _vacationsDataService.UpdateOrCreateVacationsRest(vacation);
            }
            catch (AggregateException e)
            {
                viewModel.ErrorMessage = e.InnerExceptions[0].Data["message"].ToString();
            }
            catch (Exception ex)
            {
                viewModel.ErrorMessage = ex.Message;
            }

            if (responce.LoginSuccess)
            {
                viewModel.State        = UserState.Authorized;
                viewModel.ErrorMessage = String.Empty;
            }
            else
            {
                viewModel.State        = UserState.Unauthorized;
                viewModel.ErrorMessage = responce.ErrorMessage;
            }

            return(await Helper.Complete(responce.LoginSuccess));
        }
Beispiel #28
0
 public async Task UpdateOrCreateVacationInSql(VacationInfoModel vacation)
 {
     await _vacationsDataService.UpdateOrCreateVacationsSql(vacation);
 }
Beispiel #29
0
        private async void FillData()
        {
            if (_vacationsViewModel == null)
            {
                return;
            }
            _vacationInfo = await _vacationsViewModel.GetVacationInfo(_id);

            if (_vacationsViewModel.IsOnlineMode && _vacationInfo == null)
            {
                bool result = await Relogin();

                if (result)
                {
                    _vacationInfo = await _vacationsViewModel.GetVacationInfo(_id);
                }
            }
            if (_vacationInfo == null)
            {
                Intent myIntent = new Intent(this, typeof(MainScreenActivity));
                SetResult(Result.FirstUser, myIntent);
                Exit();
                return;
            }
            _vacationError.Text        = string.Empty;
            _employee.Text             = _vacationInfo.Employee.FullName;
            _vacationType.Text         = _vacationInfo.Type.Value;
            _approver.Text             = _vacationInfo.Approver.FullName;
            _startDate                 = ConverterHelper.ConvertMillisecToDateTime(_vacationInfo.StartDate);
            _vacationStartDateBtn.Text = _startDate.ToString("d");
            _endDate = ConverterHelper.ConvertMillisecToDateTime(_vacationInfo.EndDate);
            _vacationEndDateBtn.Text = _endDate.ToString("d");
            _duration.Text           = String.Format("{0} {1}", ConverterHelper.CalculateDuration(_startDate, _endDate), _vacationsViewModel.Localaizer.Localize("days"));
            if (_vacationInfo.Status.Value.Equals(VacationStatus.Approved.ToString()))
            {
                _vacationStatus.SetTextColor(Android.Graphics.Color.DarkGreen);
                _approved = true;
                _vacationStartDateBtn.Enabled                    =
                    _vacationPickImageFromGallery.Enabled        =
                        _vacationImageView.Enabled               =
                            _vacationPickImageFromCamera.Enabled =
                                _vacationEndDateBtn.Enabled      = false;
            }
            else
            {
                _approved = false;
                if (_vacationInfo.Status.Value.Equals(VacationStatus.Rejected.ToString()))
                {
                    _vacationStatus.SetTextColor(Android.Graphics.Color.DarkRed);
                }
                else
                {
                    if (_vacationInfo.Status.Value.Equals(VacationStatus.Closed.ToString()))
                    {
                        _vacationStatus.SetTextColor(Android.Graphics.Color.Black);
                        _approved = true;
                        _vacationStartDateBtn.Enabled                    =
                            _vacationPickImageFromGallery.Enabled        =
                                _vacationImageView.Enabled               =
                                    _vacationPickImageFromCamera.Enabled =
                                        _vacationEndDateBtn.Enabled      = false;
                    }
                    else
                    {
                        _vacationStatus.SetTextColor(Android.Graphics.Color.Black);
                    }
                }
            }
            if (_vacationsViewModel.Image != null)
            {
                Bitmap bmp = BitmapFactory.DecodeByteArray(_vacationsViewModel.Image, 0, _vacationsViewModel.Image.Length);
                _vacationImageView.SetImageBitmap(bmp);
            }
            _vacationStatus.Text = _vacationInfo.Status.Value;
            var translate = _vacationsViewModel.Localaizer.Localize(_vacationInfo.Status.Value);

            if (!translate.Equals("N/A"))
            {
                _vacationStatus.Text = translate;
            }
            _labelEmployee.Text                = _vacationsViewModel.Employee;
            _lavelVacationType.Text            = _vacationsViewModel.VacationType;
            _labelApprover.Text                = _vacationsViewModel.Approver;
            _labelDuration.Text                = _vacationsViewModel.Duration;
            _labelVacationStatus.Text          = _vacationsViewModel.Status;
            _labelAttachments.Text             = _vacationsViewModel.Attachments;
            _vacationPickImageFromGallery.Text = _vacationsViewModel.Gallery;
            _vacationPickImageFromCamera.Text  = _vacationsViewModel.Camera;
        }
Beispiel #30
0
        public async Task UpdateDraftVacationInfo(VacationInfoModel vacInfo)
        {
            await _vacationManager.UpdateOrCreateVacationInSql(vacInfo);

            return;
        }