Exemplo n.º 1
0
        public static List <OutputInvoiceNoteViewModel> ConvertToOutputInvoiceNoteViewModelList(this IEnumerable <OutputInvoiceNote> OutputInvoiceNotes)
        {
            List <OutputInvoiceNoteViewModel> OutputInvoiceNoteViewModels = new List <OutputInvoiceNoteViewModel>();

            foreach (OutputInvoiceNote OutputInvoiceNote in OutputInvoiceNotes)
            {
                OutputInvoiceNoteViewModels.Add(OutputInvoiceNote.ConvertToOutputInvoiceNoteViewModel());
            }
            return(OutputInvoiceNoteViewModels);
        }
        public OutputInvoiceNote Delete(Guid identifier)
        {
            OutputInvoiceNote dbEntry = context.OutputInvoiceNotes
                                        .Union(context.ChangeTracker.Entries()
                                               .Where(x => x.State == EntityState.Added && x.Entity.GetType() == typeof(OutputInvoiceNote))
                                               .Select(x => x.Entity as OutputInvoiceNote))
                                        .FirstOrDefault(x => x.Identifier == identifier && x.Active == true);

            if (dbEntry != null)
            {
                dbEntry.Active    = false;
                dbEntry.UpdatedAt = DateTime.Now;
            }
            return(dbEntry);
        }
Exemplo n.º 3
0
        public static OutputInvoiceNote ConvertToOutputInvoiceNote(this OutputInvoiceNoteViewModel OutputInvoiceNoteViewModel)
        {
            OutputInvoiceNote OutputInvoiceNote = new OutputInvoiceNote()
            {
                Id         = OutputInvoiceNoteViewModel.Id,
                Identifier = OutputInvoiceNoteViewModel.Identifier,

                OutputInvoiceId = OutputInvoiceNoteViewModel.OutputInvoice?.Id ?? null,

                Note       = OutputInvoiceNoteViewModel.Note,
                NoteDate   = OutputInvoiceNoteViewModel.NoteDate,
                ItemStatus = OutputInvoiceNoteViewModel.ItemStatus,

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

                CreatedAt = OutputInvoiceNoteViewModel.CreatedAt,
                UpdatedAt = OutputInvoiceNoteViewModel.UpdatedAt
            };

            return(OutputInvoiceNote);
        }
        public OutputInvoiceNote Create(OutputInvoiceNote OutputInvoiceNote)
        {
            if (context.OutputInvoiceNotes.Where(x => x.Identifier != null && x.Identifier == OutputInvoiceNote.Identifier).Count() == 0)
            {
                OutputInvoiceNote.Id = 0;

                OutputInvoiceNote.Active = true;

                OutputInvoiceNote.UpdatedAt = DateTime.Now;
                OutputInvoiceNote.CreatedAt = DateTime.Now;

                context.OutputInvoiceNotes.Add(OutputInvoiceNote);
                return(OutputInvoiceNote);
            }
            else
            {
                // Load item that will be updated
                OutputInvoiceNote dbEntry = context.OutputInvoiceNotes
                                            .FirstOrDefault(x => x.Identifier == OutputInvoiceNote.Identifier && x.Active == true);

                if (dbEntry != null)
                {
                    dbEntry.CompanyId   = OutputInvoiceNote.CompanyId ?? null;
                    dbEntry.CreatedById = OutputInvoiceNote.CreatedById ?? null;

                    // Set properties
                    dbEntry.Note       = OutputInvoiceNote.Note;
                    dbEntry.NoteDate   = OutputInvoiceNote.NoteDate;
                    dbEntry.ItemStatus = OutputInvoiceNote.ItemStatus;

                    // Set timestamp
                    dbEntry.UpdatedAt = DateTime.Now;
                }

                return(dbEntry);
            }
        }
Exemplo n.º 5
0
        public static OutputInvoiceNoteViewModel ConvertToOutputInvoiceNoteViewModel(this OutputInvoiceNote OutputInvoiceNote)
        {
            OutputInvoiceNoteViewModel OutputInvoiceNoteViewModel = new OutputInvoiceNoteViewModel()
            {
                Id         = OutputInvoiceNote.Id,
                Identifier = OutputInvoiceNote.Identifier,

                OutputInvoice = OutputInvoiceNote.OutputInvoice?.ConvertToOutputInvoiceViewModelLite(),

                Note       = OutputInvoiceNote.Note,
                NoteDate   = OutputInvoiceNote.NoteDate,
                ItemStatus = OutputInvoiceNote.ItemStatus,

                IsActive = OutputInvoiceNote.Active,

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

                UpdatedAt = OutputInvoiceNote.UpdatedAt,
                CreatedAt = OutputInvoiceNote.CreatedAt
            };

            return(OutputInvoiceNoteViewModel);
        }
Exemplo n.º 6
0
        public static OutputInvoiceNoteViewModel ConvertToOutputInvoiceNoteViewModelLite(this OutputInvoiceNote OutputInvoiceNote)
        {
            OutputInvoiceNoteViewModel OutputInvoiceNoteViewModel = new OutputInvoiceNoteViewModel()
            {
                Id         = OutputInvoiceNote.Id,
                Identifier = OutputInvoiceNote.Identifier,

                Note       = OutputInvoiceNote.Note,
                NoteDate   = OutputInvoiceNote.NoteDate,
                ItemStatus = OutputInvoiceNote.ItemStatus,

                IsActive = OutputInvoiceNote.Active,

                UpdatedAt = OutputInvoiceNote.UpdatedAt,
                CreatedAt = OutputInvoiceNote.CreatedAt
            };

            return(OutputInvoiceNoteViewModel);
        }
        public List <OutputInvoiceNote> GetOutputInvoiceNotes(int companyId)
        {
            List <OutputInvoiceNote> OutputInvoiceNotes = new List <OutputInvoiceNote>();

            string queryString =
                "SELECT OutputInvoiceNoteId, OutputInvoiceNoteIdentifier, " +
                "OutputInvoiceId, OutputInvoiceIdentifier, OutputInvoiceCode, " +
                "Note, NoteDate, ItemStatus," +
                "Active, UpdatedAt, CreatedById, CreatedByFirstName, CreatedByLastName, CompanyId, CompanyName " +
                "FROM vOutputInvoiceNotes " +
                "WHERE CompanyId = @CompanyId AND Active = 1;";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandText = queryString;
                command.Parameters.Add(new SqlParameter("@CompanyId", companyId));

                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    OutputInvoiceNote outputInvoiceNote;
                    while (reader.Read())
                    {
                        outputInvoiceNote            = new OutputInvoiceNote();
                        outputInvoiceNote.Id         = Int32.Parse(reader["OutputInvoiceNoteId"].ToString());
                        outputInvoiceNote.Identifier = Guid.Parse(reader["OutputInvoiceNoteIdentifier"].ToString());

                        if (reader["OutputInvoiceId"] != DBNull.Value)
                        {
                            outputInvoiceNote.OutputInvoice            = new OutputInvoice();
                            outputInvoiceNote.OutputInvoiceId          = Int32.Parse(reader["OutputInvoiceId"].ToString());
                            outputInvoiceNote.OutputInvoice.Id         = Int32.Parse(reader["OutputInvoiceId"].ToString());
                            outputInvoiceNote.OutputInvoice.Identifier = Guid.Parse(reader["OutputInvoiceIdentifier"].ToString());
                            outputInvoiceNote.OutputInvoice.Code       = reader["OutputInvoiceCode"].ToString();
                        }

                        if (reader["Note"] != DBNull.Value)
                        {
                            outputInvoiceNote.Note = reader["Note"].ToString();
                        }
                        if (reader["NoteDate"] != DBNull.Value)
                        {
                            outputInvoiceNote.NoteDate = DateTime.Parse(reader["NoteDate"].ToString());
                        }
                        if (reader["ItemStatus"] != DBNull.Value)
                        {
                            outputInvoiceNote.ItemStatus = Int32.Parse(reader["ItemStatus"].ToString());
                        }

                        outputInvoiceNote.Active    = bool.Parse(reader["Active"].ToString());
                        outputInvoiceNote.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString());

                        if (reader["CreatedById"] != DBNull.Value)
                        {
                            outputInvoiceNote.CreatedBy           = new User();
                            outputInvoiceNote.CreatedById         = Int32.Parse(reader["CreatedById"].ToString());
                            outputInvoiceNote.CreatedBy.Id        = Int32.Parse(reader["CreatedById"].ToString());
                            outputInvoiceNote.CreatedBy.FirstName = reader["CreatedByFirstName"]?.ToString();
                            outputInvoiceNote.CreatedBy.LastName  = reader["CreatedByLastName"]?.ToString();
                        }

                        if (reader["CompanyId"] != DBNull.Value)
                        {
                            outputInvoiceNote.Company      = new Company();
                            outputInvoiceNote.CompanyId    = Int32.Parse(reader["CompanyId"].ToString());
                            outputInvoiceNote.Company.Id   = Int32.Parse(reader["CompanyId"].ToString());
                            outputInvoiceNote.Company.Name = reader["CompanyName"].ToString();
                        }

                        OutputInvoiceNotes.Add(outputInvoiceNote);
                    }
                }
            }
            return(OutputInvoiceNotes);


            //List<OutputInvoiceNote> OutputInvoiceNotes = context.OutputInvoiceNotes
            //    .Include(x => x.OutputInvoice)
            //    .Include(x => x.Company)
            //    .Include(x => x.CreatedBy)
            //    .Where(x => x.Active == true && x.CompanyId == companyId)
            //    .AsNoTracking()
            //    .ToList();

            //return OutputInvoiceNotes;
        }
        public List <OutputInvoiceNote> GetOutputInvoiceNotesNewerThen(int companyId, DateTime lastUpdateTime)
        {
            List <OutputInvoiceNote> OutputInvoiceNotes = new List <OutputInvoiceNote>();

            string queryString =
                "SELECT OutputInvoiceNoteId, OutputInvoiceNoteIdentifier, " +
                "OutputInvoiceId, OutputInvoiceIdentifier, OutputInvoiceCode, " +
                "Note, NoteDate, ItemStatus, " +
                "Active, UpdatedAt, CreatedById, CreatedByFirstName, CreatedByLastName, CompanyId, CompanyName " +
                "FROM vOutputInvoiceNotes " +
                "WHERE CompanyId = @CompanyId " +
                "AND CONVERT(DATETIME, CONVERT(VARCHAR(20), UpdatedAt, 120)) > CONVERT(DATETIME, CONVERT(VARCHAR(20), @LastUpdateTime, 120));";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandText = queryString;
                command.Parameters.Add(new SqlParameter("@CompanyId", companyId));
                command.Parameters.Add(new SqlParameter("@LastUpdateTime", lastUpdateTime));

                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    OutputInvoiceNote outputInvoiceNote;
                    while (reader.Read())
                    {
                        outputInvoiceNote            = new OutputInvoiceNote();
                        outputInvoiceNote.Id         = Int32.Parse(reader["OutputInvoiceNoteId"].ToString());
                        outputInvoiceNote.Identifier = Guid.Parse(reader["OutputInvoiceNoteIdentifier"].ToString());

                        if (reader["OutputInvoiceId"] != DBNull.Value)
                        {
                            outputInvoiceNote.OutputInvoice            = new OutputInvoice();
                            outputInvoiceNote.OutputInvoiceId          = Int32.Parse(reader["OutputInvoiceId"].ToString());
                            outputInvoiceNote.OutputInvoice.Id         = Int32.Parse(reader["OutputInvoiceId"].ToString());
                            outputInvoiceNote.OutputInvoice.Identifier = Guid.Parse(reader["OutputInvoiceIdentifier"].ToString());
                            outputInvoiceNote.OutputInvoice.Code       = reader["OutputInvoiceCode"].ToString();
                        }


                        if (reader["Note"] != DBNull.Value)
                        {
                            outputInvoiceNote.Note = reader["Note"].ToString();
                        }
                        if (reader["NoteDate"] != DBNull.Value)
                        {
                            outputInvoiceNote.NoteDate = DateTime.Parse(reader["NoteDate"].ToString());
                        }
                        if (reader["ItemStatus"] != DBNull.Value)
                        {
                            outputInvoiceNote.ItemStatus = Int32.Parse(reader["ItemStatus"].ToString());
                        }

                        outputInvoiceNote.Active    = bool.Parse(reader["Active"].ToString());
                        outputInvoiceNote.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString());

                        if (reader["CreatedById"] != DBNull.Value)
                        {
                            outputInvoiceNote.CreatedBy           = new User();
                            outputInvoiceNote.CreatedById         = Int32.Parse(reader["CreatedById"].ToString());
                            outputInvoiceNote.CreatedBy.Id        = Int32.Parse(reader["CreatedById"].ToString());
                            outputInvoiceNote.CreatedBy.FirstName = reader["CreatedByFirstName"]?.ToString();
                            outputInvoiceNote.CreatedBy.LastName  = reader["CreatedByLastName"]?.ToString();
                        }

                        if (reader["CompanyId"] != DBNull.Value)
                        {
                            outputInvoiceNote.Company      = new Company();
                            outputInvoiceNote.CompanyId    = Int32.Parse(reader["CompanyId"].ToString());
                            outputInvoiceNote.Company.Id   = Int32.Parse(reader["CompanyId"].ToString());
                            outputInvoiceNote.Company.Name = reader["CompanyName"].ToString();
                        }

                        OutputInvoiceNotes.Add(outputInvoiceNote);
                    }
                }
            }
            return(OutputInvoiceNotes);
        }