public PhysicalPersonAttachmentListResponse GetPhysicalPersonAttachmentsByPhysicalPerson(int companyId, Guid PhysicalPersonIdentifier)
        {
            PhysicalPersonAttachmentListResponse     response = new PhysicalPersonAttachmentListResponse();
            List <PhysicalPersonAttachmentViewModel> PhysicalPersonAttachments = new List <PhysicalPersonAttachmentViewModel>();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        @"FROM PhysicalPersonAttachments att 
                            WHERE (@PhysicalPersonIdentifier IS NULL OR @PhysicalPersonIdentifier = '' OR att.PhysicalPersonIdentifier LIKE @PhysicalPersonIdentifier) 
                            AND att.CompanyId = @CompanyId 
                            ORDER BY att.Id ASC ", db);

                    selectCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", ((object)PhysicalPersonIdentifier) ?? DBNull.Value);
                    selectCommand.Parameters.AddWithValue("@CompanyId", companyId);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    while (query.Read())
                    {
                        PhysicalPersonAttachmentViewModel dbEntry = Read(query);
                        PhysicalPersonAttachments.Add(dbEntry);
                    }
                    response.PhysicalPersonAttachments = PhysicalPersonAttachments;

                    selectCommand = new SqliteCommand(
                        @"SELECT Count(*) 
                            FROM PhysicalPersonAttachments att
                            WHERE(@PhysicalPersonIdentifier IS NULL OR @PhysicalPersonIdentifier = '' OR att.PhysicalPersonIdentifier LIKE @PhysicalPersonIdentifier)
                            AND att.CompanyId = @CompanyId
                            ORDER BY att.IsSynced, att.Id DESC", db);

                    selectCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", ((object)PhysicalPersonIdentifier) ?? DBNull.Value);
                    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.PhysicalPersonAttachments = new List <PhysicalPersonAttachmentViewModel>();
                    return(response);
                }
                db.Close();
            }
            response.Success = true;
            response.PhysicalPersonAttachments = PhysicalPersonAttachments;
            return(response);
        }
        public PhysicalPersonResponse Create(PhysicalPersonAttachmentViewModel attachment)
        {
            PhysicalPersonResponse response = new PhysicalPersonResponse();

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

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

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, attachment);
                    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);
            }
        }
        public PhysicalPersonAttachmentResponse Create(PhysicalPersonAttachmentViewModel PhysicalPersonAttachment)
        {
            PhysicalPersonAttachmentResponse response = new PhysicalPersonAttachmentResponse();

            try
            {
                response = WpfApiHandler.SendToApi <PhysicalPersonAttachmentViewModel, PhysicalPersonAttachmentResponse>(PhysicalPersonAttachment, "Create");
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public static PhysicalPersonAttachmentViewModel ConvertToPhysicalPersonAttachmentViewModelLite(this PhysicalPersonAttachment PhysicalPersonAttachment)
        {
            PhysicalPersonAttachmentViewModel PhysicalPersonAttachmentViewModel = new PhysicalPersonAttachmentViewModel()
            {
                Id         = PhysicalPersonAttachment.Id,
                Identifier = PhysicalPersonAttachment.Identifier,

                Code = PhysicalPersonAttachment.Code,

                OK       = PhysicalPersonAttachment.OK,
                IsActive = PhysicalPersonAttachment.Active,

                UpdatedAt = PhysicalPersonAttachment.UpdatedAt,
                CreatedAt = PhysicalPersonAttachment.CreatedAt
            };

            return(PhysicalPersonAttachmentViewModel);
        }
        private static PhysicalPersonAttachmentViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            PhysicalPersonAttachmentViewModel dbEntry = new PhysicalPersonAttachmentViewModel();

            dbEntry.Id         = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.Code       = SQLiteHelper.GetString(query, ref counter);
            dbEntry.OK         = SQLiteHelper.GetBoolean(query, ref counter);

            dbEntry.PhysicalPerson = SQLiteHelper.GetPhysicalPerson(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);
        }
Пример #6
0
        public JsonResult Create([FromBody] PhysicalPersonAttachmentViewModel c)
        {
            PhysicalPersonAttachmentResponse response;

            try
            {
                response = this.PhysicalPersonAttachmentService.Create(c);
            }
            catch (Exception ex)
            {
                response = null;
                Console.WriteLine(ex.Message);
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
Пример #7
0
        public PhysicalPersonAttachmentResponse Create(PhysicalPersonAttachmentViewModel PhysicalPersonAttachment)
        {
            PhysicalPersonAttachmentResponse response = new PhysicalPersonAttachmentResponse();

            try
            {
                response.PhysicalPersonAttachment = unitOfWork.GetPhysicalPersonAttachmentRepository().Create(PhysicalPersonAttachment.ConvertToPhysicalPersonAttachment())
                                                    .ConvertToPhysicalPersonAttachmentViewModel();

                unitOfWork.Save();

                response.Success = true;
            } catch (Exception ex)
            {
                response         = new PhysicalPersonAttachmentResponse();
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, PhysicalPersonAttachmentViewModel PhysicalPersonAttachment)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", PhysicalPersonAttachment.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", PhysicalPersonAttachment.Identifier);
            insertCommand.Parameters.AddWithValue("@Code", ((object)PhysicalPersonAttachment.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@OK", ((object)PhysicalPersonAttachment.OK) ?? DBNull.Value);


            insertCommand.Parameters.AddWithValue("@PhysicalPersonId", ((object)PhysicalPersonAttachment.PhysicalPerson?.Id) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", ((object)PhysicalPersonAttachment.PhysicalPerson?.Identifier) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@PhysicalPersonCode", ((object)PhysicalPersonAttachment.PhysicalPerson?.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@PhysicalPersonName", ((object)PhysicalPersonAttachment.PhysicalPerson?.Name) ?? DBNull.Value);

            insertCommand.Parameters.AddWithValue("@IsSynced", PhysicalPersonAttachment.IsSynced);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)PhysicalPersonAttachment.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 static PhysicalPersonAttachment ConvertToPhysicalPersonAttachment(this PhysicalPersonAttachmentViewModel PhysicalPersonAttachmentViewModel)
        {
            PhysicalPersonAttachment PhysicalPersonAttachment = new PhysicalPersonAttachment()
            {
                Id         = PhysicalPersonAttachmentViewModel.Id,
                Identifier = PhysicalPersonAttachmentViewModel.Identifier,

                Code = PhysicalPersonAttachmentViewModel.Code,

                PhysicalPersonId = PhysicalPersonAttachmentViewModel.PhysicalPerson?.Id ?? null,

                OK     = PhysicalPersonAttachmentViewModel.OK,
                Active = PhysicalPersonAttachmentViewModel.IsActive,

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

                CreatedAt = PhysicalPersonAttachmentViewModel.CreatedAt,
                UpdatedAt = PhysicalPersonAttachmentViewModel.UpdatedAt
            };

            return(PhysicalPersonAttachment);
        }
        public static PhysicalPersonAttachmentViewModel ConvertToPhysicalPersonAttachmentViewModel(this PhysicalPersonAttachment PhysicalPersonAttachment)
        {
            PhysicalPersonAttachmentViewModel PhysicalPersonAttachmentViewModel = new PhysicalPersonAttachmentViewModel()
            {
                Id         = PhysicalPersonAttachment.Id,
                Identifier = PhysicalPersonAttachment.Identifier,

                Code = PhysicalPersonAttachment.Code,

                PhysicalPerson = PhysicalPersonAttachment.PhysicalPerson?.ConvertToPhysicalPersonViewModelLite(),

                OK       = PhysicalPersonAttachment.OK,
                IsActive = PhysicalPersonAttachment.Active,

                CreatedBy = PhysicalPersonAttachment.CreatedBy?.ConvertToUserViewModelLite(),
                Company   = PhysicalPersonAttachment.Company?.ConvertToCompanyViewModelLite(),

                UpdatedAt = PhysicalPersonAttachment.UpdatedAt,
                CreatedAt = PhysicalPersonAttachment.CreatedAt
            };

            return(PhysicalPersonAttachmentViewModel);
        }