Пример #1
0
        public static List <PhysicalPersonNoteViewModel> ConvertToPhysicalPersonNoteViewModelList(this IEnumerable <PhysicalPersonNote> PhysicalPersonNotes)
        {
            List <PhysicalPersonNoteViewModel> PhysicalPersonNoteViewModels = new List <PhysicalPersonNoteViewModel>();

            foreach (PhysicalPersonNote PhysicalPersonNote in PhysicalPersonNotes)
            {
                PhysicalPersonNoteViewModels.Add(PhysicalPersonNote.ConvertToPhysicalPersonNoteViewModel());
            }
            return(PhysicalPersonNoteViewModels);
        }
Пример #2
0
        public PhysicalPersonNote Delete(Guid identifier)
        {
            PhysicalPersonNote dbEntry = context.PhysicalPersonNotes
                                         .Union(context.ChangeTracker.Entries()
                                                .Where(x => x.State == EntityState.Added && x.Entity.GetType() == typeof(PhysicalPersonNote))
                                                .Select(x => x.Entity as PhysicalPersonNote))
                                         .FirstOrDefault(x => x.Identifier == identifier);

            if (dbEntry != null)
            {
                dbEntry.Active    = false;
                dbEntry.UpdatedAt = DateTime.Now;
            }
            return(dbEntry);
        }
Пример #3
0
        public static PhysicalPersonNote ConvertToPhysicalPersonNote(this PhysicalPersonNoteViewModel PhysicalPersonNoteViewModel)
        {
            PhysicalPersonNote PhysicalPersonNote = new PhysicalPersonNote()
            {
                Id         = PhysicalPersonNoteViewModel.Id,
                Identifier = PhysicalPersonNoteViewModel.Identifier,

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

                Note       = PhysicalPersonNoteViewModel.Note,
                NoteDate   = PhysicalPersonNoteViewModel.NoteDate,
                ItemStatus = PhysicalPersonNoteViewModel.ItemStatus,

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

                CreatedAt = PhysicalPersonNoteViewModel.CreatedAt,
                UpdatedAt = PhysicalPersonNoteViewModel.UpdatedAt
            };

            return(PhysicalPersonNote);
        }
Пример #4
0
        public PhysicalPersonNote Create(PhysicalPersonNote PhysicalPersonNote)
        {
            if (context.PhysicalPersonNotes.Where(x => x.Identifier != null && x.Identifier == PhysicalPersonNote.Identifier).Count() == 0)
            {
                PhysicalPersonNote.Id = 0;

                PhysicalPersonNote.Active = true;

                PhysicalPersonNote.UpdatedAt = DateTime.Now;
                PhysicalPersonNote.CreatedAt = DateTime.Now;

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

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

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


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

                return(dbEntry);
            }
        }
Пример #5
0
        public List <PhysicalPersonNote> GetPhysicalPersonNotes(int companyId)
        {
            List <PhysicalPersonNote> PhysicalPersonNotes = new List <PhysicalPersonNote>();

            string queryString =
                "SELECT PhysicalPersonNoteId, PhysicalPersonNoteIdentifier, " +
                "PhysicalPersonId, PhysicalPersonIdentifier, PhysicalPersonCode, PhysicalPersonName, " +
                "Note, NoteDate, ItemStatus, " +
                "Active, UpdatedAt, CreatedById, CreatedByFirstName, CreatedByLastName, CompanyId, CompanyName " +
                "FROM vPhysicalPersonNotes " +
                "WHERE CompanyId = @CompanyId;";

            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())
                {
                    PhysicalPersonNote physicalPersonNote;
                    while (reader.Read())
                    {
                        physicalPersonNote            = new PhysicalPersonNote();
                        physicalPersonNote.Id         = Int32.Parse(reader["PhysicalPersonNoteId"].ToString());
                        physicalPersonNote.Identifier = Guid.Parse(reader["PhysicalPersonNoteIdentifier"].ToString());

                        if (reader["PhysicalPersonId"] != DBNull.Value)
                        {
                            physicalPersonNote.PhysicalPerson            = new PhysicalPerson();
                            physicalPersonNote.PhysicalPersonId          = Int32.Parse(reader["PhysicalPersonId"].ToString());
                            physicalPersonNote.PhysicalPerson.Id         = Int32.Parse(reader["PhysicalPersonId"].ToString());
                            physicalPersonNote.PhysicalPerson.Identifier = Guid.Parse(reader["PhysicalPersonIdentifier"].ToString());
                            physicalPersonNote.PhysicalPerson.Code       = reader["PhysicalPersonCode"].ToString();
                            physicalPersonNote.PhysicalPerson.Name       = reader["PhysicalPersonName"].ToString();
                        }

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

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

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

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

                        PhysicalPersonNotes.Add(physicalPersonNote);
                    }
                }
            }
            return(PhysicalPersonNotes);


            //List<PhysicalPersonNote> PhysicalPersonNotes = context.PhysicalPersonNotes
            //    .Include(x => x.PhysicalPerson)
            //    .Include(x => x.Company)
            //    .Include(x => x.CreatedBy)
            //    .Where(x => x.Active == true && x.CompanyId == companyId)
            //    .AsNoTracking()
            //    .ToList();

            //return PhysicalPersonNotes;
        }
Пример #6
0
        public static PhysicalPersonNoteViewModel ConvertToPhysicalPersonNoteViewModelLite(this PhysicalPersonNote PhysicalPersonNote)
        {
            PhysicalPersonNoteViewModel PhysicalPersonNoteViewModel = new PhysicalPersonNoteViewModel()
            {
                Id         = PhysicalPersonNote.Id,
                Identifier = PhysicalPersonNote.Identifier,

                Note       = PhysicalPersonNote.Note,
                NoteDate   = PhysicalPersonNote.NoteDate,
                ItemStatus = PhysicalPersonNote.ItemStatus,

                IsActive = PhysicalPersonNote.Active,

                UpdatedAt = PhysicalPersonNote.UpdatedAt,
                CreatedAt = PhysicalPersonNote.CreatedAt
            };

            return(PhysicalPersonNoteViewModel);
        }
Пример #7
0
        public static PhysicalPersonNoteViewModel ConvertToPhysicalPersonNoteViewModel(this PhysicalPersonNote PhysicalPersonNote)
        {
            PhysicalPersonNoteViewModel PhysicalPersonNoteViewModel = new PhysicalPersonNoteViewModel()
            {
                Id         = PhysicalPersonNote.Id,
                Identifier = PhysicalPersonNote.Identifier,

                PhysicalPerson = PhysicalPersonNote.PhysicalPerson?.ConvertToPhysicalPersonViewModelLite(),

                Note       = PhysicalPersonNote.Note,
                NoteDate   = PhysicalPersonNote.NoteDate,
                ItemStatus = PhysicalPersonNote.ItemStatus,

                IsActive = PhysicalPersonNote.Active,

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

                UpdatedAt = PhysicalPersonNote.UpdatedAt,
                CreatedAt = PhysicalPersonNote.CreatedAt
            };

            return(PhysicalPersonNoteViewModel);
        }