Beispiel #1
0
        public BusinessPartnerTypeResponse Create(BusinessPartnerTypeViewModel businessPartnerType)
        {
            BusinessPartnerTypeResponse response = new BusinessPartnerTypeResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

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

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, businessPartnerType);
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Beispiel #2
0
        public BusinessPartnerTypeListResponse GetBusinessPartnerTypesByPage(int companyId, BusinessPartnerTypeViewModel businessPartnerTypeSearchObject, int currentPage = 1, int itemsPerPage = 50)
        {
            BusinessPartnerTypeListResponse     response             = new BusinessPartnerTypeListResponse();
            List <BusinessPartnerTypeViewModel> BusinessPartnerTypes = new List <BusinessPartnerTypeViewModel>();

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

                    selectCommand.Parameters.AddWithValue("@Name", ((object)businessPartnerTypeSearchObject.Search_Name) != null ? "%" + businessPartnerTypeSearchObject.Search_Name + "%" : "");
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);
                    selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage);
                    selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        BusinessPartnerTypeViewModel dbEntry = Read(query);
                        BusinessPartnerTypes.Add(dbEntry);
                    }

                    selectCommand = new SqliteCommand(
                        "SELECT Count(*) " +
                        "FROM BusinessPartnerTypes " +
                        "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " +
                        "AND CompanyId = @CompanyId;", db);
                    selectCommand.Parameters.AddWithValue("@Name", ((object)businessPartnerTypeSearchObject.Search_Name) != null ? "%" + businessPartnerTypeSearchObject.Search_Name + "%" : "");
                    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.BusinessPartnerTypes = new List <BusinessPartnerTypeViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.BusinessPartnerTypes = BusinessPartnerTypes;
            return(response);
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            BusinessPartnerTypeViewModel businessPartnerType = new BusinessPartnerTypeViewModel();

            businessPartnerType.Identifier = Guid.NewGuid();

            BusinessPartner_Type_AddEdit addEditForm = new BusinessPartner_Type_AddEdit(businessPartnerType, true);

            addEditForm.BusinessPartnerTypeCreatedUpdated += new BusinessPartnerTypeHandler(SyncData);
            FlyoutHelper.OpenFlyout(this, ((string)Application.Current.FindResource("Podaci_o_vrsti")), 95, addEditForm);
        }
Beispiel #4
0
        public BusinessPartner_Type_AddEdit(BusinessPartnerTypeViewModel businessPartnerTypeViewModel, bool isCreateProcess)
        {
            // Initialize service
            this.businessPartnerTypeService = DependencyResolver.Kernel.Get <IBusinessPartnerTypeService>();

            InitializeComponent();

            this.DataContext = this;

            CurrentBusinessPartnerType = businessPartnerTypeViewModel;
            IsCreateProcess            = isCreateProcess;

            txtName.Focus();
        }
        public BusinessPartnerTypeResponse Create(BusinessPartnerTypeViewModel re)
        {
            BusinessPartnerTypeResponse response = new BusinessPartnerTypeResponse();

            try
            {
                response = WpfApiHandler.SendToApi <BusinessPartnerTypeViewModel, BusinessPartnerTypeResponse>(re, "Create");
            }
            catch (Exception ex)
            {
                response.BusinessPartnerType = new BusinessPartnerTypeViewModel();
                response.Success             = false;
                response.Message             = ex.Message;
            }

            return(response);
        }
Beispiel #6
0
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, BusinessPartnerTypeViewModel businessPartnerType)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", businessPartnerType.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", businessPartnerType.Identifier);
            insertCommand.Parameters.AddWithValue("@Code", ((object)businessPartnerType.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Name", ((object)businessPartnerType.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@IsBuyer", ((object)businessPartnerType.IsBuyer) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@IsSupplier", ((object)businessPartnerType.IsSupplier) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@IsSynced", businessPartnerType.IsSynced);
            insertCommand.Parameters.AddWithValue("@ItemStatus", ((object)businessPartnerType.ItemStatus) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)businessPartnerType.UpdatedAt) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id);
            insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName);
            insertCommand.Parameters.AddWithValue("@CompanyId", MainWindow.CurrentCompany.Id);
            insertCommand.Parameters.AddWithValue("@CompanyName", MainWindow.CurrentCompany.CompanyName);

            return(insertCommand);
        }
        public BusinessPartnerTypeResponse Delete(Guid identifier)
        {
            BusinessPartnerTypeResponse response = new BusinessPartnerTypeResponse();

            try
            {
                BusinessPartnerTypeViewModel re = new BusinessPartnerTypeViewModel();
                re.Identifier = identifier;
                response      = WpfApiHandler.SendToApi <BusinessPartnerTypeViewModel, BusinessPartnerTypeResponse>(re, "Delete");
            }
            catch (Exception ex)
            {
                response.BusinessPartnerType = new BusinessPartnerTypeViewModel();
                response.Success             = false;
                response.Message             = ex.Message;
            }

            return(response);
        }
Beispiel #8
0
        private BusinessPartnerTypeViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            BusinessPartnerTypeViewModel dbEntry = new BusinessPartnerTypeViewModel();

            dbEntry.Id         = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.Code       = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Name       = SQLiteHelper.GetString(query, ref counter);
            dbEntry.IsBuyer    = SQLiteHelper.GetBoolean(query, ref counter);
            dbEntry.IsSupplier = SQLiteHelper.GetBoolean(query, ref counter);
            dbEntry.ItemStatus = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.IsSynced   = SQLiteHelper.GetBoolean(query, ref counter);
            dbEntry.UpdatedAt  = SQLiteHelper.GetDateTime(query, ref counter);
            dbEntry.CreatedBy  = SQLiteHelper.GetCreatedBy(query, ref counter);
            dbEntry.Company    = SQLiteHelper.GetCompany(query, ref counter);

            return(dbEntry);
        }
Beispiel #9
0
        public BusinessPartnerTypeListResponse GetBusinessPartnerTypesByBusinessPartner(int companyId, Guid businessPartnerIdentifier)
        {
            BusinessPartnerTypeListResponse     response             = new BusinessPartnerTypeListResponse();
            List <BusinessPartnerTypeViewModel> businessPartnerTypes = new List <BusinessPartnerTypeViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM BusinessPartnerTypes " +
                        "WHERE Identifier IN (SELECT BusinessPartnerTypeIdentifier from BusinessPartnerBusinessPartnerTypes where BusinessPartnerIdentifier = @BusinessPartnerIdentifier) " +
                        "AND CompanyId = @CompanyId " +
                        "ORDER BY IsSynced, Id DESC;", db);

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

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        BusinessPartnerTypeViewModel dbEntry = Read(query);
                        businessPartnerTypes.Add(dbEntry);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage       = error.Message;
                    response.Success              = false;
                    response.Message              = error.Message;
                    response.BusinessPartnerTypes = new List <BusinessPartnerTypeViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.BusinessPartnerTypes = businessPartnerTypes;
            return(response);
        }
        public BusinessPartnerTypeResponse Create(BusinessPartnerTypeViewModel re)
        {
            BusinessPartnerTypeResponse response = new BusinessPartnerTypeResponse();

            try
            {
                BusinessPartnerType addedBusinessPartnerType = unitOfWork.GetBusinessPartnerTypeRepository().Create(re.ConvertToBusinessPartnerType());
                unitOfWork.Save();
                response.BusinessPartnerType = addedBusinessPartnerType.ConvertToBusinessPartnerTypeViewModel();
                response.Success             = true;
            }
            catch (Exception ex)
            {
                response.BusinessPartnerType = new BusinessPartnerTypeViewModel();
                response.Success             = false;
                response.Message             = ex.Message;
            }

            return(response);
        }
Beispiel #11
0
        public JsonResult Delete([FromBody] BusinessPartnerTypeViewModel businessPartnerType)
        {
            BusinessPartnerTypeResponse response = new BusinessPartnerTypeResponse();

            try
            {
                response = this.businessPartnerTypeService.Delete(businessPartnerType.Identifier);
            }
            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 BusinessPartner_Types_AddEdit(BusinessPartnerViewModel businessPartner)
        {
            businessPartnerService     = DependencyResolver.Kernel.Get <IBusinessPartnerService>();
            businessPartnerTypeService = DependencyResolver.Kernel.Get <IBusinessPartnerTypeService>();

            InitializeComponent();

            this.DataContext = this;

            CurrentBusinessPartner                  = businessPartner;
            CurrentBusinessPartnerTypeDG            = new BusinessPartnerTypeViewModel();
            CurrentBusinessPartnerTypeDG.Identifier = Guid.NewGuid();
            CurrentBusinessPartnerTypeDG.ItemStatus = ItemStatus.Added;

            Thread displayThread = new Thread(() => PopulateBusinessPartnerTypeData());

            displayThread.IsBackground = true;
            displayThread.Start();

            btnSaveType.Focus();
        }
        public static BusinessPartnerTypeViewModel ConvertToBusinessPartnerTypeViewModelLite(this BusinessPartnerType businessPartnerType)
        {
            BusinessPartnerTypeViewModel businessPartnerTypeViewModel = new BusinessPartnerTypeViewModel()
            {
                Id         = businessPartnerType.Id,
                Identifier = businessPartnerType.Identifier,

                Code = businessPartnerType.Code,
                Name = businessPartnerType.Name,

                IsBuyer    = businessPartnerType.IsBuyer,
                IsSupplier = businessPartnerType.IsSupplier,
                ItemStatus = businessPartnerType.ItemStatus,
                IsActive   = businessPartnerType.Active,

                UpdatedAt = businessPartnerType.UpdatedAt,
                CreatedAt = businessPartnerType.CreatedAt
            };

            return(businessPartnerTypeViewModel);
        }
Beispiel #14
0
        public BusinessPartnerTypeResponse GetBusinessPartnerType(Guid identifier)
        {
            BusinessPartnerTypeResponse  response            = new BusinessPartnerTypeResponse();
            BusinessPartnerTypeViewModel businessPartnerType = new BusinessPartnerTypeViewModel();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM BusinessPartnerTypes " +
                        "WHERE Identifier = @Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@Identifier", identifier);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        BusinessPartnerTypeViewModel dbEntry = Read(query);
                        businessPartnerType = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage      = error.Message;
                    response.Success             = false;
                    response.Message             = error.Message;
                    response.BusinessPartnerType = new BusinessPartnerTypeViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success             = true;
            response.BusinessPartnerType = businessPartnerType;
            return(response);
        }
        public static BusinessPartnerType ConvertToBusinessPartnerType(this BusinessPartnerTypeViewModel businessPartnerTypeViewModel)
        {
            BusinessPartnerType businessPartnerType = new BusinessPartnerType()
            {
                Id         = businessPartnerTypeViewModel.Id,
                Identifier = businessPartnerTypeViewModel.Identifier,

                Code = businessPartnerTypeViewModel.Code,
                Name = businessPartnerTypeViewModel.Name,

                IsBuyer     = businessPartnerTypeViewModel.IsBuyer,
                IsSupplier  = businessPartnerTypeViewModel.IsSupplier,
                ItemStatus  = businessPartnerTypeViewModel.ItemStatus,
                Active      = businessPartnerTypeViewModel.IsActive,
                CreatedById = businessPartnerTypeViewModel.CreatedBy?.Id ?? null,
                CompanyId   = businessPartnerTypeViewModel.Company?.Id ?? null,

                CreatedAt = businessPartnerTypeViewModel.CreatedAt,
                UpdatedAt = businessPartnerTypeViewModel.UpdatedAt
            };

            return(businessPartnerType);
        }
Beispiel #16
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (String.IsNullOrEmpty(CurrentBusinessPartnerType.Name))
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Ime_vrste"));
                return;
            }

            #endregion

            Thread th = new Thread(() =>
            {
                SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke"));
                SaveButtonEnabled = false;

                CurrentBusinessPartnerType.IsSynced = false;

                CurrentBusinessPartnerType.Company = new CompanyViewModel()
                {
                    Id = MainWindow.CurrentCompanyId
                };
                CurrentBusinessPartnerType.CreatedBy = new UserViewModel()
                {
                    Id = MainWindow.CurrentUserId
                };


                //BusinessPartnerTypeResponse response = new BusinessPartnerTypeSQLiteRepository().Delete(CurrentBusinessPartnerType.Identifier);
                BusinessPartnerTypeResponse response = new BusinessPartnerTypeSQLiteRepository().Create(CurrentBusinessPartnerType);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_čuvanjaUzvičnik"));
                    SaveButtonContent       = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled       = true;
                    return;
                }

                response = businessPartnerTypeService.Create(CurrentBusinessPartnerType);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Podaci_su_sačuvani_u_lokaluUzvičnikTačka_Greška_kod_čuvanja_na_serveruUzvičnik"));
                    SaveButtonContent       = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled       = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SaveButtonContent         = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled         = true;

                    BusinessPartnerTypeCreatedUpdated();

                    if (IsCreateProcess)
                    {
                        CurrentBusinessPartnerType            = new BusinessPartnerTypeViewModel();
                        CurrentBusinessPartnerType.Identifier = Guid.NewGuid();

                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            txtName.Focus();
                        })
                            );
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            FlyoutHelper.CloseFlyout(this);
                        })
                            );
                    }
                }
            });
            th.IsBackground = true;
            th.Start();
            txtName.Focus();
        }