Exemplo n.º 1
0
        public LimitationEmailResponse Create(LimitationEmailViewModel LimitationEmail)
        {
            LimitationEmailResponse response = new LimitationEmailResponse();

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

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

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, LimitationEmail);
                    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);
            }
        }
Exemplo n.º 2
0
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, LimitationEmailViewModel LimitationEmail)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", LimitationEmail.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", LimitationEmail.Identifier);
            insertCommand.Parameters.AddWithValue("@Name", ((object)LimitationEmail.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@LastName", ((object)LimitationEmail.LastName) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Email", ((object)LimitationEmail.Email) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@IsSynced", LimitationEmail.IsSynced);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)LimitationEmail.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);
        }
Exemplo n.º 3
0
        public LimitationEmailResponse Create(LimitationEmailViewModel re)
        {
            LimitationEmailResponse response = new LimitationEmailResponse();

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

            return(response);
        }
Exemplo n.º 4
0
        private LimitationEmailViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            LimitationEmailViewModel dbEntry = new LimitationEmailViewModel();

            dbEntry.Id         = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.Name       = SQLiteHelper.GetString(query, ref counter);
            dbEntry.LastName   = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Email      = SQLiteHelper.GetString(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);
        }
Exemplo n.º 5
0
        public LimitationEmailResponse Delete(Guid identifier)
        {
            LimitationEmailResponse response = new LimitationEmailResponse();

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

            return(response);
        }
        public static LimitationEmailViewModel ConvertToLimitationEmailViewModelLite(this LimitationEmail LimitationEmail)
        {
            LimitationEmailViewModel LimitationEmailViewModel = new LimitationEmailViewModel()
            {
                Id         = LimitationEmail.Id,
                Identifier = LimitationEmail.Identifier,

                Name     = LimitationEmail.Name,
                LastName = LimitationEmail.LastName,
                Email    = LimitationEmail.Email,

                IsActive = LimitationEmail.Active,

                UpdatedAt = LimitationEmail.UpdatedAt,
                CreatedAt = LimitationEmail.CreatedAt
            };

            return(LimitationEmailViewModel);
        }
Exemplo n.º 7
0
        public LimitationEmailResponse Create(LimitationEmailViewModel re)
        {
            LimitationEmailResponse response = new LimitationEmailResponse();

            try
            {
                LimitationEmail addedLimitationEmail = unitOfWork.GetLimitationEmailRepository().Create(re.ConvertToLimitationEmail());
                unitOfWork.Save();
                response.LimitationEmail = addedLimitationEmail.ConvertToLimitationEmailViewModel();
                response.Success         = true;
            }
            catch (Exception ex)
            {
                response.LimitationEmail = new LimitationEmailViewModel();
                response.Success         = false;
                response.Message         = ex.Message;
            }

            return(response);
        }
        public JsonResult Delete([FromBody] LimitationEmailViewModel LimitationEmail)
        {
            LimitationEmailResponse response = new LimitationEmailResponse();

            try
            {
                response = this.LimitationEmailService.Delete(LimitationEmail.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 static LimitationEmail ConvertToLimitationEmail(this LimitationEmailViewModel LimitationEmailViewModel)
        {
            LimitationEmail LimitationEmail = new LimitationEmail()
            {
                Id         = LimitationEmailViewModel.Id,
                Identifier = LimitationEmailViewModel.Identifier,

                Name     = LimitationEmailViewModel.Name,
                LastName = LimitationEmailViewModel.LastName,
                Email    = LimitationEmailViewModel.Email,

                Active = LimitationEmailViewModel.IsActive,

                CreatedById = LimitationEmailViewModel.CreatedBy?.Id ?? null,
                CompanyId   = LimitationEmailViewModel.Company?.Id ?? null,

                CreatedAt = LimitationEmailViewModel.CreatedAt,
                UpdatedAt = LimitationEmailViewModel.UpdatedAt
            };

            return(LimitationEmail);
        }
Exemplo n.º 10
0
        public LimitationEmailResponse GetLimitationEmail(Guid identifier)
        {
            LimitationEmailResponse  response        = new LimitationEmailResponse();
            LimitationEmailViewModel LimitationEmail = new LimitationEmailViewModel();

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

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        LimitationEmail = Read(query);
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage  = error.Message;
                    response.Success         = false;
                    response.Message         = error.Message;
                    response.LimitationEmail = new LimitationEmailViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success         = true;
            response.LimitationEmail = LimitationEmail;
            return(response);
        }
Exemplo n.º 11
0
        public LimitationEmailListResponse GetLimitationEmailsByPage(int companyId, LimitationEmailViewModel LimitationEmailSearchObject, int currentPage = 1, int itemsPerPage = 50)
        {
            LimitationEmailListResponse     response         = new LimitationEmailListResponse();
            List <LimitationEmailViewModel> LimitationEmails = new List <LimitationEmailViewModel>();

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

                    selectCommand.Parameters.AddWithValue("@Name", ((object)LimitationEmailSearchObject.Search_Name) != null ? "%" + LimitationEmailSearchObject.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())
                    {
                        LimitationEmails.Add(Read(query));
                    }



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

                    selectCommand.Parameters.AddWithValue("@Name", ((object)LimitationEmailSearchObject.Search_Name) != null ? "%" + LimitationEmailSearchObject.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.LimitationEmails = new List <LimitationEmailViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success          = true;
            response.LimitationEmails = LimitationEmails;
            return(response);
        }
Exemplo n.º 12
0
 private void btnCancel_Click(object sender, RoutedEventArgs e)
 {
     CurrentLimitationEmail = new LimitationEmailViewModel();
 }
Exemplo n.º 13
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Thread th = new Thread(() =>
            {
                SaveButtonContent = " Čuvanje u toku... ";
                SaveButtonEnabled = false;

                if (CurrentLimitationEmail.Identifier == Guid.Empty)
                {
                    CurrentLimitationEmail.Identifier = Guid.NewGuid();
                }
                CurrentLimitationEmail.Company = new CompanyViewModel()
                {
                    Id = MainWindow.CurrentCompanyId
                };
                CurrentLimitationEmail.CreatedBy = new UserViewModel()
                {
                    Id = MainWindow.CurrentUserId
                };

                CurrentLimitationEmail.IsSynced = false;

                LimitationEmailResponse response = new LimitationEmailSQLiteRepository().Delete(CurrentLimitationEmail.Identifier);
                response = new LimitationEmailSQLiteRepository().Create(CurrentLimitationEmail);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = "Greška kod lokalnog čuvanja!";
                    SaveButtonContent       = " SAČUVAJ ";
                    SaveButtonEnabled       = true;
                    return;
                }

                response = limitationEmailService.Create(CurrentLimitationEmail);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = "Podaci su sačuvani u lokalu!. Greška kod čuvanja na serveru!";
                    SaveButtonContent       = " SAČUVAJ ";
                    SaveButtonEnabled       = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = "Podaci su uspešno sačuvani!";
                    SaveButtonContent         = " SAČUVAJ ";
                    SaveButtonEnabled         = true;

                    DisplayEmailData();

                    CurrentLimitationEmail            = new LimitationEmailViewModel();
                    CurrentLimitationEmail.Identifier = Guid.NewGuid();

                    Application.Current.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Normal,
                        new Action(() =>
                    {
                        txtName.Focus();
                    })
                        );
                }
            });

            th.IsBackground = true;
            th.Start();
        }