Example #1
0
        public EmployeeProfessionItemListResponse Sync(SyncEmployeeProfessionItemRequest request)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

            try
            {
                response.EmployeeProfessionItems = new List <EmployeeProfessionItemViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.EmployeeProfessionItems.AddRange(unitOfWork.GetEmployeeProfessionRepository()
                                                              .GetEmployeeItemsNewerThan(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                              ?.ConvertToEmployeeProfessionViewModelList() ?? new List <EmployeeProfessionItemViewModel>());
                }
                else
                {
                    response.EmployeeProfessionItems.AddRange(unitOfWork.GetEmployeeProfessionRepository()
                                                              .GetEmployeeItems(request.CompanyId)
                                                              ?.ConvertToEmployeeProfessionViewModelList() ?? new List <EmployeeProfessionItemViewModel>());
                }

                unitOfWork.Save();

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

            return(response);
        }
Example #2
0
        public EmployeeProfessionItemListResponse GetEmployeeItemsNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

            try
            {
                if (lastUpdateTime != null)
                {
                    response.EmployeeProfessionItems = unitOfWork.GetEmployeeProfessionRepository()
                                                       .GetEmployeeItemsNewerThan(companyId, (DateTime)lastUpdateTime)
                                                       .ConvertToEmployeeProfessionViewModelList();
                }
                else
                {
                    response.EmployeeProfessionItems = unitOfWork.GetEmployeeProfessionRepository()
                                                       .GetEmployeeItems(companyId)
                                                       .ConvertToEmployeeProfessionViewModelList();
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeProfessionItems = new List <EmployeeProfessionItemViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Example #3
0
        public EmployeeProfessionItemListResponse Sync(SyncEmployeeProfessionItemRequest request)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncEmployeeProfessionItemRequest, EmployeeProfessionItemViewModel, EmployeeProfessionItemListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.EmployeeProfessionItems = new List <EmployeeProfessionItemViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Example #4
0
        public EmployeeProfessionItemListResponse GetEmployeeItems(int companyId)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

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

                response = WpfApiHandler.GetFromApi <List <EmployeeProfessionItemViewModel>, EmployeeProfessionItemListResponse>("GetEmployeeItems", parameters);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Example #5
0
        public EmployeeProfessionItemListResponse GetEmployeeItems(int companyId)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

            try
            {
                response.EmployeeProfessionItems = unitOfWork.GetEmployeeProfessionRepository()
                                                   .GetEmployeeItems(companyId)
                                                   .ConvertToEmployeeProfessionViewModelList();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeProfessionItems = new List <EmployeeProfessionItemViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Example #6
0
        public EmployeeProfessionItemListResponse GetEmployeeItemsNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

            try
            {
                response = WpfApiHandler.GetFromApi <List <EmployeeProfessionItemViewModel>, EmployeeProfessionItemListResponse>("GetEmployeeItemsNewerThen", new Dictionary <string, string>()
                {
                    { "CompanyId", companyId.ToString() },
                    { "LastUpdateTime", lastUpdateTime.ToString() }
                });
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public JsonResult Sync([FromBody] SyncEmployeeProfessionItemRequest request)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

            try
            {
                response = this.EmployeeItemService.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 GetEmployeeItemsNewerThen(int CompanyId, DateTime?lastUpdateTime)
        {
            EmployeeProfessionItemListResponse response = new EmployeeProfessionItemListResponse();

            try
            {
                response = EmployeeItemService.GetEmployeeItemsNewerThen(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 EmployeeProfessionItemListResponse GetEmployeeProfessionsByEmployee(int companyId, Guid EmployeeIdentifier)
        {
            EmployeeProfessionItemListResponse     response = new EmployeeProfessionItemListResponse();
            List <EmployeeProfessionItemViewModel> EmployeeProfessionItems = new List <EmployeeProfessionItemViewModel>();

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

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

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        EmployeeProfessionItemViewModel dbEntry = Read(query);
                        EmployeeProfessionItems.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage          = error.Message;
                    response.Success                 = false;
                    response.Message                 = error.Message;
                    response.EmployeeProfessionItems = new List <EmployeeProfessionItemViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.EmployeeProfessionItems = EmployeeProfessionItems;
            return(response);
        }
        public void Sync(IEmployeeProfessionService EmployeeItemService, Action <int, int> callback = null)
        {
            try
            {
                SyncEmployeeProfessionItemRequest request = new SyncEmployeeProfessionItemRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                EmployeeProfessionItemListResponse response = EmployeeItemService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.EmployeeProfessionItems?.Count ?? 0;
                    List <EmployeeProfessionItemViewModel> employeeProfessionItemsFromDB = response.EmployeeProfessionItems;

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

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

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

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

                                    insertCommand = AddCreateParameters(insertCommand, employeeProfessionItem);
                                    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;
            }
        }