// POST: odata/QuickBooksDesktopExports
        public IActionResult Post([FromBody] QuickBooksDesktopExport quickBooksDesktopExport)
        {
            var currentUser = CurrentUser();

            // Auto-generated.
            quickBooksDesktopExport.UserId = currentUser.Id;

            try
            {
                // Validate the model.
                ModelState.ClearValidationState(nameof(quickBooksDesktopExport));
                if (!TryValidateModel(quickBooksDesktopExport, nameof(quickBooksDesktopExport)))
                {
                    return(BadRequest());
                }

                _context.QuickBooksDesktopExports.Add(quickBooksDesktopExport);

                _context.SaveChanges();

                return(Ok(quickBooksDesktopExport));
            }
            catch (DbUpdateException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task RefreshSyncs()
        {
            Status            = "Downloading your exports";
            IsRefreshEnabled  = false;
            IsContinueEnabled = false;
            OnPropertyChanged("Status");
            OnPropertyChanged("IsRefreshEnabled");
            OnPropertyChanged("IsContinueEnabled");

            // Build request to get syncs.
            var request = new RestRequest("odata/QuickBooksDesktopExports?$count=true&$top=20&$skip=0&$orderby=CreatedAt DESC", Method.GET);

            // Execute request.
            var response = await client.ExecuteAsync <ODataResponse <QuickBooksDesktopExport> >(request);

            if ((response.ResponseStatus == ResponseStatus.Completed) &&
                (response.StatusCode == System.Net.HttpStatusCode.OK))
            {
                Syncs = new ObservableCollection <QuickBooksDesktopExport>(response.Data.Value);
                OnPropertyChanged("Syncs");

                if (Syncs.Count == 0)
                {
                    Status            = "Uh oh, you do not have any QuickBooks Desktop exports";
                    SelectedSync      = null;
                    IsContinueEnabled = false;
                    OnPropertyChanged("Status");
                    OnPropertyChanged("SelectedSync");
                    OnPropertyChanged("IsContinueEnabled");
                }
                else
                {
                    Status            = "";
                    SelectedSync      = Syncs[0];
                    IsContinueEnabled = true;
                    OnPropertyChanged("Status");
                    OnPropertyChanged("SelectedSync");
                    OnPropertyChanged("IsContinueEnabled");
                }

                IsRefreshEnabled = true;
                OnPropertyChanged("IsRefreshEnabled");
            }
            else
            {
                Syncs             = new ObservableCollection <QuickBooksDesktopExport>();
                IsRefreshEnabled  = true;
                IsContinueEnabled = false;
                Status            = response.ErrorMessage;
                OnPropertyChanged("Syncs");
                OnPropertyChanged("IsRefreshEnabled");
                OnPropertyChanged("IsContinueEnabled");
                OnPropertyChanged("Status");
            }
        }
Exemplo n.º 3
0
        // POST: odata/QuickBooksDesktopExports
        public IHttpActionResult Post(QuickBooksDesktopExport quickBooksDesktopExport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var currentUser = CurrentUser();

            // Set defaults.
            quickBooksDesktopExport.UserId = currentUser.Id;

            try
            {
                db.QuickBooksDesktopExports.Add(quickBooksDesktopExport);
                db.SaveChanges();

                return(Created(quickBooksDesktopExport));
            }
            catch (DbEntityValidationException ex)
            {
                string message = "";

                foreach (var eve in ex.EntityValidationErrors)
                {
                    foreach (var ve in eve.ValidationErrors)
                    {
                        message += string.Format("{0} has error '{1}'; ", ve.PropertyName, ve.ErrorMessage);
                    }
                }

                return(BadRequest(message));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (DbUpdateException ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }