public PhysicalPersonProfessionListResponse Sync(SyncPhysicalPersonProfessionRequest request)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                response.PhysicalPersonProfessions = new List <PhysicalPersonProfessionViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.PhysicalPersonProfessions.AddRange(unitOfWork.GetPhysicalPersonProfessionRepository()
                                                                .GetPhysicalPersonItemsNewerThan(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                                ?.ConvertToPhysicalPersonProfessionViewModelList() ?? new List <PhysicalPersonProfessionViewModel>());
                }
                else
                {
                    response.PhysicalPersonProfessions.AddRange(unitOfWork.GetPhysicalPersonProfessionRepository()
                                                                .GetPhysicalPersonItems(request.CompanyId)
                                                                ?.ConvertToPhysicalPersonProfessionViewModelList() ?? new List <PhysicalPersonProfessionViewModel>());
                }

                unitOfWork.Save();

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.PhysicalPersonProfessions = new List <PhysicalPersonProfessionViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public PhysicalPersonProfessionListResponse GetPhysicalPersonItemsNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                if (lastUpdateTime != null)
                {
                    response.PhysicalPersonProfessions = unitOfWork.GetPhysicalPersonProfessionRepository()
                                                         .GetPhysicalPersonItemsNewerThan(companyId, (DateTime)lastUpdateTime)
                                                         .ConvertToPhysicalPersonProfessionViewModelList();
                }
                else
                {
                    response.PhysicalPersonProfessions = unitOfWork.GetPhysicalPersonProfessionRepository()
                                                         .GetPhysicalPersonItems(companyId)
                                                         .ConvertToPhysicalPersonProfessionViewModelList();
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.PhysicalPersonProfessions = new List <PhysicalPersonProfessionViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public PhysicalPersonProfessionListResponse Sync(SyncPhysicalPersonProfessionRequest request)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncPhysicalPersonProfessionRequest, PhysicalPersonProfessionViewModel, PhysicalPersonProfessionListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.PhysicalPersonProfessions = new List <PhysicalPersonProfessionViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public PhysicalPersonProfessionListResponse GetPhysicalPersonItems(int companyId)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("CompanyID", companyId.ToString());

                response = WpfApiHandler.GetFromApi <List <PhysicalPersonProfessionViewModel>, PhysicalPersonProfessionListResponse>("GetPhysicalPersonItems", parameters);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public JsonResult Sync([FromBody] SyncPhysicalPersonProfessionRequest request)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                response = this.PhysicalPersonItemService.Sync(request);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
        public JsonResult GetPhysicalPersonItemsNewerThen(int CompanyId, DateTime?lastUpdateTime)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                response = PhysicalPersonItemService.GetPhysicalPersonItemsNewerThen(CompanyId, lastUpdateTime);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }
            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
        public PhysicalPersonProfessionListResponse GetPhysicalPersonItems(int companyId)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                response.PhysicalPersonProfessions = unitOfWork.GetPhysicalPersonProfessionRepository()
                                                     .GetPhysicalPersonItems(companyId)
                                                     .ConvertToPhysicalPersonProfessionViewModelList();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.PhysicalPersonProfessions = new List <PhysicalPersonProfessionViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public PhysicalPersonProfessionListResponse GetPhysicalPersonItemsNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            PhysicalPersonProfessionListResponse response = new PhysicalPersonProfessionListResponse();

            try
            {
                response = WpfApiHandler.GetFromApi <List <PhysicalPersonProfessionViewModel>, PhysicalPersonProfessionListResponse>("GetPhysicalPersonItemsNewerThen", new Dictionary <string, string>()
                {
                    { "CompanyId", companyId.ToString() },
                    { "LastUpdateTime", lastUpdateTime.ToString() }
                });
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Ejemplo n.º 9
0
        public PhysicalPersonProfessionListResponse GetPhysicalPersonProfessionsByPhysicalPerson(int companyId, Guid PhysicalPersonIdentifier)
        {
            PhysicalPersonProfessionListResponse     response = new PhysicalPersonProfessionListResponse();
            List <PhysicalPersonProfessionViewModel> PhysicalPersonProfessions = new List <PhysicalPersonProfessionViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM  PhysicalPersonProfessions " +
                        "WHERE PhysicalPersonIdentifier = @PhysicalPersonIdentifier " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC;", db);

                    selectCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", PhysicalPersonIdentifier);
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        PhysicalPersonProfessionViewModel dbEntry = Read(query);
                        PhysicalPersonProfessions.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage            = error.Message;
                    response.Success                   = false;
                    response.Message                   = error.Message;
                    response.PhysicalPersonProfessions = new List <PhysicalPersonProfessionViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.PhysicalPersonProfessions = PhysicalPersonProfessions;
            return(response);
        }
Ejemplo n.º 10
0
        public void Sync(IPhysicalPersonProfessionService physicalPersonItemService, Action <int, int> callback = null)
        {
            try
            {
                SyncPhysicalPersonProfessionRequest request = new SyncPhysicalPersonProfessionRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                PhysicalPersonProfessionListResponse response = physicalPersonItemService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.PhysicalPersonProfessions?.Count ?? 0;
                    List <PhysicalPersonProfessionViewModel> items = response.PhysicalPersonProfessions;

                    using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
                    {
                        db.Open();
                        using (var transaction = db.BeginTransaction())
                        {
                            SqliteCommand deleteCommand = db.CreateCommand();
                            deleteCommand.CommandText = "DELETE FROM PhysicalPersonProfessions WHERE Identifier = @Identifier";

                            SqliteCommand insertCommand = db.CreateCommand();
                            insertCommand.CommandText = SqlCommandInsertPart;

                            foreach (var item in items)
                            {
                                deleteCommand.Parameters.AddWithValue("@Identifier", item.Identifier);
                                deleteCommand.ExecuteNonQuery();
                                deleteCommand.Parameters.Clear();

                                if (item.IsActive)
                                {
                                    item.IsSynced = true;

                                    insertCommand = AddCreateParameters(insertCommand, item);
                                    insertCommand.ExecuteNonQuery();
                                    insertCommand.Parameters.Clear();

                                    syncedItems++;
                                    callback?.Invoke(syncedItems, toSync);
                                }
                            }

                            transaction.Commit();
                        }
                        db.Close();
                    }
                }
                else
                {
                    throw new Exception(response.Message);
                }
            }
            catch (Exception ex)
            {
                MainWindow.ErrorMessage = ex.Message;
            }
        }