public LicenceTypeListResponse GetLicenceTypesNewerThen(int companyId, DateTime?lastUpdateTime)
        {
            LicenceTypeListResponse response = new LicenceTypeListResponse();

            try
            {
                if (lastUpdateTime != null)
                {
                    response.LicenceTypes = unitOfWork.GetLicenceTypeRepository()
                                            .GetLicenceTypesNewerThen(companyId, (DateTime)lastUpdateTime)
                                            .ConvertToLicenceTypeViewModelList();
                }
                else
                {
                    response.LicenceTypes = unitOfWork.GetLicenceTypeRepository()
                                            .GetLicenceTypes(companyId)
                                            .ConvertToLicenceTypeViewModelList();
                }
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.LicenceTypes = new List <LicenceTypeViewModel>();
                response.Success      = false;
                response.Message      = ex.Message;
            }

            return(response);
        }
        public LicenceTypeListResponse Sync(SyncLicenceTypeRequest request)
        {
            LicenceTypeListResponse response = new LicenceTypeListResponse();

            try
            {
                response.LicenceTypes = new List <LicenceTypeViewModel>();

                if (request.LastUpdatedAt != null)
                {
                    response.LicenceTypes.AddRange(unitOfWork.GetLicenceTypeRepository()
                                                   .GetLicenceTypesNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt)
                                                   ?.ConvertToLicenceTypeViewModelList() ?? new List <LicenceTypeViewModel>());
                }
                else
                {
                    response.LicenceTypes.AddRange(unitOfWork.GetLicenceTypeRepository()
                                                   .GetLicenceTypes(request.CompanyId)
                                                   ?.ConvertToLicenceTypeViewModelList() ?? new List <LicenceTypeViewModel>());
                }

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

            return(response);
        }
        public LicenceTypeListResponse GetLicenceTypesForPopup(int companyId, string filterString)
        {
            LicenceTypeListResponse     response     = new LicenceTypeListResponse();
            List <LicenceTypeViewModel> LicenceTypes = new List <LicenceTypeViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM LicenceTypes " +
                        "WHERE ((@Code IS NULL OR @Code = '' OR Code LIKE @Code) " +
                        "OR (@Category IS NULL OR @Category = '' OR Category LIKE @Category)) " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC " +
                        "LIMIT @ItemsPerPage;", db);

                    selectCommand.Parameters.AddWithValue("@Code", ((object)filterString) != null ? "%" + filterString + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Category", ((object)filterString) != null ? "%" + filterString + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", ((object)filterString) != null ? companyId : 0);
                    selectCommand.Parameters.AddWithValue("@ItemsPerPage", 100);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        LicenceTypeViewModel dbEntry = Read(query);
                        LicenceTypes.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.LicenceTypes   = new List <LicenceTypeViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success      = true;
            response.LicenceTypes = LicenceTypes;
            return(response);
        }
        public LicenceTypeListResponse Sync(SyncLicenceTypeRequest request)
        {
            LicenceTypeListResponse response = new LicenceTypeListResponse();

            try
            {
                response = WpfApiHandler.SendToApi <SyncLicenceTypeRequest, LicenceTypeViewModel, LicenceTypeListResponse>(request, "Sync");
            }
            catch (Exception ex)
            {
                response.LicenceTypes = new List <LicenceTypeViewModel>();
                response.Success      = false;
                response.Message      = ex.Message;
            }

            return(response);
        }
        public LicenceTypeListResponse GetLicenceTypes(int companyId)
        {
            LicenceTypeListResponse response = new LicenceTypeListResponse();

            try
            {
                response.LicenceTypes = unitOfWork.GetLicenceTypeRepository().GetLicenceTypes(companyId)
                                        .ConvertToLicenceTypeViewModelList();
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.LicenceTypes = new List <LicenceTypeViewModel>();
                response.Success      = false;
                response.Message      = ex.Message;
            }

            return(response);
        }
Пример #6
0
        public JsonResult GetLicenceTypes(int companyId)
        {
            LicenceTypeListResponse response = new LicenceTypeListResponse();

            try
            {
                response = licenceTypeService.GetLicenceTypes(companyId);
            }
            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
            }));
        }
Пример #7
0
        public JsonResult Sync([FromBody] SyncLicenceTypeRequest request)
        {
            LicenceTypeListResponse response = new LicenceTypeListResponse();

            try
            {
                response = this.licenceTypeService.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 LicenceTypeListResponse GetLicenceTypes(int companyId)
        {
            LicenceTypeListResponse response = new LicenceTypeListResponse();

            try
            {
                response = WpfApiHandler.GetFromApi <List <LicenceTypeViewModel>, LicenceTypeListResponse>("GetLicenceTypes", new Dictionary <string, string>()
                {
                    { "CompanyId", companyId.ToString() }
                });
            }
            catch (Exception ex)
            {
                response.LicenceTypes = new List <LicenceTypeViewModel>();
                response.Success      = false;
                response.Message      = ex.Message;
            }

            return(response);
        }
        public LicenceTypeListResponse GetLicenceTypesByPage(int companyId, LicenceTypeViewModel licenceTypeSearchObject, int currentPage = 1, int itemsPerPage = 50)
        {
            LicenceTypeListResponse     response     = new LicenceTypeListResponse();
            List <LicenceTypeViewModel> LicenceTypes = new List <LicenceTypeViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM LicenceTypes " +
                        "WHERE (@Category IS NULL OR @Category = '' OR Category LIKE @Category) " +
                        "AND (@Description IS NULL OR @Description = '' OR Description LIKE @Description) " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC " +
                        "LIMIT @ItemsPerPage OFFSET @Offset;", db);

                    selectCommand.Parameters.AddWithValue("@Category", ((object)licenceTypeSearchObject.Search_Category) != null ? "%" + licenceTypeSearchObject.Search_Category + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Description", ((object)licenceTypeSearchObject.Search_Description) != null ? "%" + licenceTypeSearchObject.Search_Description + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);
                    selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage);
                    selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        LicenceTypeViewModel dbEntry = Read(query);
                        LicenceTypes.Add(dbEntry);
                    }

                    selectCommand = new SqliteCommand(
                        "SELECT Count(*) " +
                        "FROM LicenceTypes " +
                        "WHERE (@Category IS NULL OR @Category = '' OR Category LIKE @Category) " +
                        "AND (@Description IS NULL OR @Description = '' OR Description LIKE @Description) " +
                        "AND CompanyId = @CompanyId ;", db);

                    selectCommand.Parameters.AddWithValue("@Category", ((object)licenceTypeSearchObject.Search_Category) != null ? "%" + licenceTypeSearchObject.Search_Category + "%" : "");
                    selectCommand.Parameters.AddWithValue("@Description", ((object)licenceTypeSearchObject.Search_Description) != null ? "%" + licenceTypeSearchObject.Search_Description + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);


                    query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        response.TotalItems = query.GetInt32(0);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    response.LicenceTypes   = new List <LicenceTypeViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success      = true;
            response.LicenceTypes = LicenceTypes;
            return(response);
        }
        public void Sync(ILicenceTypeService licenceTypeService, Action <int, int> callback = null)
        {
            try
            {
                SyncLicenceTypeRequest request = new SyncLicenceTypeRequest();
                request.CompanyId     = MainWindow.CurrentCompanyId;
                request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId);

                int toSync      = 0;
                int syncedItems = 0;

                LicenceTypeListResponse response = licenceTypeService.Sync(request);
                if (response.Success)
                {
                    toSync = response?.LicenceTypes?.Count ?? 0;
                    List <LicenceTypeViewModel> licenceTypesFromDB = response.LicenceTypes;

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

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

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

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

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