public EmployeeLicenceItemListResponse GetEmployeeItemsNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

            try
            {
                if (lastUpdateTime != null)
                {
                    response.EmployeeLicenceItems = unitOfWork.GetEmployeeLicenceRepository()
                                                    .GetEmployeeItemsNewerThan(companyId, (DateTime)lastUpdateTime)
                                                    .ConvertToEmployeeLicenceViewModelList();
                }
                else
                {
                    response.EmployeeLicenceItems = unitOfWork.GetEmployeeLicenceRepository()
                                                    .GetEmployeeItems(companyId)
                                                    .ConvertToEmployeeLicenceViewModelList();
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeLicenceItems = new List <EmployeeLicenceItemViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public EmployeeLicenceItemListResponse Sync(SyncEmployeeLicenceItemRequest request)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

            try
            {
                response.EmployeeLicenceItems = new List <EmployeeLicenceItemViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.EmployeeLicenceItems.AddRange(unitOfWork.GetEmployeeLicenceRepository()
                                                           .GetEmployeeItemsNewerThan(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                           ?.ConvertToEmployeeLicenceViewModelList() ?? new List <EmployeeLicenceItemViewModel>());
                }
                else
                {
                    response.EmployeeLicenceItems.AddRange(unitOfWork.GetEmployeeLicenceRepository()
                                                           .GetEmployeeItems(request.CompanyId)
                                                           ?.ConvertToEmployeeLicenceViewModelList() ?? new List <EmployeeLicenceItemViewModel>());
                }

                unitOfWork.Save();

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

            return(response);
        }
        public EmployeeLicenceItemListResponse Sync(SyncEmployeeLicenceItemRequest request)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncEmployeeLicenceItemRequest, EmployeeLicenceItemViewModel, EmployeeLicenceItemListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.EmployeeLicenceItems = new List <EmployeeLicenceItemViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public EmployeeLicenceItemListResponse GetEmployeeItems(int companyId)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

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

                response = WpfApiHandler.GetFromApi <List <EmployeeLicenceItemViewModel>, EmployeeLicenceItemListResponse>("GetEmployeeItems", parameters);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public EmployeeLicenceItemListResponse GetEmployeeItemsNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

            try
            {
                response = WpfApiHandler.GetFromApi <List <EmployeeLicenceItemViewModel>, EmployeeLicenceItemListResponse>("GetEmployeeItemsNewerThen", new Dictionary <string, string>()
                {
                    { "CompanyId", companyId.ToString() },
                    { "LastUpdateTime", lastUpdateTime.ToString() }
                });
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public EmployeeLicenceItemListResponse GetEmployeeItems(int companyId)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

            try
            {
                response.EmployeeLicenceItems = unitOfWork.GetEmployeeLicenceRepository()
                                                .GetEmployeeItems(companyId)
                                                .ConvertToEmployeeLicenceViewModelList();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.EmployeeLicenceItems = new List <EmployeeLicenceItemViewModel>();
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Пример #7
0
        public JsonResult Sync([FromBody] SyncEmployeeLicenceItemRequest request)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

            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
            }));
        }
Пример #8
0
        public JsonResult GetEmployeeItemsNewerThen(int CompanyId, DateTime?lastUpdateTime)
        {
            EmployeeLicenceItemListResponse response = new EmployeeLicenceItemListResponse();

            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 EmployeeLicenceItemListResponse GetEmployeeLicencesByEmployee(int companyId, Guid EmployeeIdentifier)
        {
            EmployeeLicenceItemListResponse     response             = new EmployeeLicenceItemListResponse();
            List <EmployeeLicenceItemViewModel> EmployeeLicenceItems = new List <EmployeeLicenceItemViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM  EmployeeLicenceItems " +
                        "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())
                    {
                        EmployeeLicenceItemViewModel dbEntry = Read(query);
                        EmployeeLicenceItems.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage       = error.Message;
                    response.Success              = false;
                    response.Message              = error.Message;
                    response.EmployeeLicenceItems = new List <EmployeeLicenceItemViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.EmployeeLicenceItems = EmployeeLicenceItems;
            return(response);
        }
        public void Sync(IEmployeeLicenceService EmployeeItemService, Action <int, int> callback = null)
        {
            try
            {
                SyncEmployeeLicenceItemRequest request = new SyncEmployeeLicenceItemRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                EmployeeLicenceItemListResponse response = EmployeeItemService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.EmployeeLicenceItems?.Count ?? 0;
                    List <EmployeeLicenceItemViewModel> employeeLicenceItemsFromDB = response.EmployeeLicenceItems;

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

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

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

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

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