public async Task SaveVacationInfo (VTSModel newItem) { ModelConverter converter = new ModelConverter (); SQLiteService sqliteService; try { sqliteService = new SQLiteService (_sqlitePlatform, await _fileSystem.GetPath ("VTS")); } catch { sqliteService = null; } VacationInfoDTO dt = converter.ConvertToVacationInfoDTO (newItem); await sqliteService.Insert<VacationInfoDTO> (dt); RestService restService = new RestService ("/api/Vacations", Server); var req = await restService.Post<VacationInfoModel> (converter.ConvertToVacationInfoModel(newItem)); }
public async Task<List<VTSModel>> GetVTSList () { ModelConverter converter = new ModelConverter (); List<VacationInfoModel> listVacationInfoModel; try { RestService restService = new RestService ("/api/Vacations", Server); listVacationInfoModel = await restService.Get<VacationInfoModel> (); } catch (AggregateException e) { //ErrorMessage = e.InnerExceptions [0].Data ["message"].ToString (); listVacationInfoModel = null; } SQLiteService sqliteService; try { sqliteService = new SQLiteService (_sqlitePlatform, await _fileSystem.GetPath ("VTS")); } catch { sqliteService = null; } List<VTSModel> VTSViewModelList = new List<VTSModel> (); VTSModel newItem; listVacationInfoModel = new VacationInfoMockModel ().Vacations; if (listVacationInfoModel != null) { foreach (VacationInfoModel info in listVacationInfoModel) { newItem = converter.ConvertToVTSModel (info); VTSViewModelList.Add (newItem); if (sqliteService != null) { await sqliteService.Insert<VacationInfoDTO> (converter.ConvertToVacationInfoDTO (newItem)); } } } else if(sqliteService != null) { List<VacationInfoDTO> vacationInfoList = await sqliteService.Get<VacationInfoDTO> (); if (vacationInfoList != null) { foreach (VacationInfoDTO info in vacationInfoList) { VTSViewModelList.Add (converter.ConvertToVTSModel (info)); } } } return VTSViewModelList; }
private void OnCreateBtnClick (object sender, EventArgs e) { var index = _tabController.SelectedIndex; DateTime startDate = DateTime.Parse (((UIButton)View.ViewWithTag (STARTDATE_TAG + index)).Title (UIControlState.Normal)); DateTime endDate = DateTime.Parse (((UIButton)View.ViewWithTag (ENDDATE_TAG + index)).Title (UIControlState.Normal)); if (startDate > endDate) { ((UILabel)View.ViewWithTag (ERROR_TAG + index)).Text = _localizer.Localize("dateError"); } else { VTSModelTmp.VTSModel.VacationType = _tabController.ViewControllers [index].TabBarItem.Title; VTSModelTmp.VTSModel.StartDate = (long)(startDate - new DateTime (1970, 1, 1)).TotalMilliseconds; VTSModelTmp.VTSModel.EndDate = (long)(endDate - new DateTime (1970, 1, 1)).TotalMilliseconds; UIImageView imageView = (UIImageView)View.ViewWithTag (IMAGE_TAG + index); if (imageView.Image != null) { using (NSData imageData = imageView.Image.AsPNG ()) { Byte[] myByteArray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy (imageData.Bytes, myByteArray, 0, Convert.ToInt32 (imageData.Length)); VTSModelTmp.VTSModel.Image = myByteArray; } } ModelConverter modelConverter = new ModelConverter (); VTSModelTmp.VTSModel.Date = modelConverter.ConvertDateToString (VTSModelTmp.VTSModel.StartDate, VTSModelTmp.VTSModel.EndDate); this.NavigationController.PopViewController(true); ControllerResult (this,"Create"); } }
private async void onItemCreateButtonClicked(object sender, EventArgs e) { var packageName =Application.Context.PackageName.ToString(); int position = VacationInfoCreateTabsFragment._viewPager.CurrentItem; int viewId =_container.Context.Resources.GetIdentifier ("view_"+position, "id" ,packageName); View currentView = _container.FindViewById (viewId); TextView ItemError = currentView.FindViewById<TextView> (Resource.Id.ItemError); TextView ItemType = currentView.FindViewById<TextView> (Resource.Id.ItemType); Button ItemStartDateBtn = currentView.FindViewById<Button> (Resource.Id.ItemStartDateBtn); Button ItemEndDateBtn = currentView.FindViewById<Button> (Resource.Id.ItemEndDateBtn); DateTime startDate = DateTime.Parse(ItemStartDateBtn.Text); DateTime endDate = DateTime.Parse(ItemEndDateBtn.Text); if (startDate > endDate) { ItemError.SetTextColor (Android.Graphics.Color.DarkRed); ItemError.Visibility = ViewStates.Visible; } else { VTSModelSingleton.VTSModel.VacationType = ItemType.Text; VTSModelSingleton.VTSModel.StartDate = (long)(startDate - new DateTime (1970, 1, 1)).TotalMilliseconds; VTSModelSingleton.VTSModel.EndDate = (long)(endDate - new DateTime (1970, 1, 1)).TotalMilliseconds; VTSModelSingleton.VTSModel.Status = "redCircle.png"; ModelConverter converter = new ModelConverter (); VTSModelSingleton.VTSModel.Date = converter.ConvertDateToString (VTSModelSingleton.VTSModel.StartDate, VTSModelSingleton.VTSModel.EndDate); if (_imageUri != null) { PlatformConverter platformConverter = new PlatformConverter (_container.Context); VTSModelSingleton.VTSModel.Image = platformConverter.GetByteByURI (_imageUri); } await ViewDispose (); Intent myIntent = new Intent (_container.Context, typeof(MainActivity)); myIntent.PutExtra ("Type", "Create"); ((Activity)_container.Context).SetResult (Result.Ok, myIntent); ((Activity)_container.Context).Finish(); } }
private async void onVacationUpdateButtonClicked(object sender, EventArgs e) { if (_startDate > _endDate) { _vacationError.SetTextColor (Android.Graphics.Color.DarkRed); _vacationError.Visibility = ViewStates.Visible; } else { VTSModelSingleton.VTSModel.StartDate = (long)(_startDate - new DateTime (1970, 1, 1)).TotalMilliseconds; VTSModelSingleton.VTSModel.EndDate = (long)(_endDate - new DateTime (1970, 1, 1)).TotalMilliseconds; if (_imageUri != null) { PlatformConverter platformConverter = new PlatformConverter (this.ApplicationContext); VTSModelSingleton.VTSModel.Image = platformConverter.GetByteByURI (_imageUri); } ModelConverter modelConverter = new ModelConverter (); VTSModelSingleton.VTSModel.Date = modelConverter.ConvertDateToString (VTSModelSingleton.VTSModel.StartDate, VTSModelSingleton.VTSModel.EndDate); Intent myIntent = new Intent (this, typeof(MainActivity)); SetResult (Result.Ok, myIntent); Finish (); await ViewDispose (); } }
public async Task<VTSModel> GetVacationInfo (string id) { ModelConverter converter = new ModelConverter (); SQLiteService sqliteService; try { sqliteService = new SQLiteService (_sqlitePlatform, await _fileSystem.GetPath ("VTS")); } catch { sqliteService = null; } VacationInfoDTO info =await sqliteService.Get<VacationInfoDTO> (id); return converter.ConvertToVTSModel(info); }
public async Task DeleteVacationInfo (string id) { ModelConverter converter = new ModelConverter (); SQLiteService sqliteService; try { sqliteService = new SQLiteService (_sqlitePlatform, await _fileSystem.GetPath ("VTS")); } catch { sqliteService = null; } await sqliteService.Delete<VacationInfoDTO> (id); RestService restService = new RestService ("/api/Vacations", Server); var req = await restService.Delete(id); }
private void OnUpdateBtnClick (object sender, EventArgs e) { DateTime startDate = DateTime.Parse (_vacationStartDateBtn.Title (UIControlState.Normal)); DateTime endDate = DateTime.Parse (_vacationEndDateBtn.Title (UIControlState.Normal)); if (startDate > endDate) { _vacationError.Text = _localizer.Localize("dateError"); } else { VTSModelTmp.VTSModel.StartDate = (long)(startDate - new DateTime (1970, 1, 1)).TotalMilliseconds; VTSModelTmp.VTSModel.EndDate = (long)(endDate - new DateTime (1970, 1, 1)).TotalMilliseconds; if (_vacationImageView.Image != null) { using (NSData imageData = _vacationImageView.Image.AsPNG ()) { Byte[] myByteArray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy (imageData.Bytes, myByteArray, 0, Convert.ToInt32 (imageData.Length)); VTSModelTmp.VTSModel.Image = myByteArray; } } ModelConverter modelConverter = new ModelConverter (); VTSModelTmp.VTSModel.Date = modelConverter.ConvertDateToString (VTSModelTmp.VTSModel.StartDate, VTSModelTmp.VTSModel.EndDate); this.NavigationController.PopViewController(true); ControllerResult (this,"Edit"); } }