예제 #1
0
        /// <summary>
        /// Converts entity of <see cref="Account"/> in <see cref="DalAccount"/>
        /// </summary>
        /// <param name="baseAccount"> Entity for converting from <see cref="Account"/> </param>
        /// <returns> Entity of  <see cref="DalAccount"/> </returns>
        public static DalAccount ToDalAccount(this Account baseAccount)
        {
            if (baseAccount == null)
            {
                return(null);
            }

            var dalPerson = new DalPerson
            {
                FirstName    = baseAccount.Owner.FirstName,
                LastName     = baseAccount.Owner.LastName,
                SecondName   = baseAccount.Owner.SecondName,
                SerialNumber = baseAccount.Owner.SerialNumber,
                Accounts     = baseAccount.Owner.Accounts.ToDalAccount(),
                Contact      = new DalContactData
                {
                    Email = baseAccount.Owner.Email
                }
            };

            return(new DalAccount
            {
                Number = baseAccount.Number,
                Owner = dalPerson,
                InvoiceAmount = baseAccount.InvoiceAmount,
                Bonuses = baseAccount.Bonuses,
                AccountType = baseAccount.AccountType.ToDalAccountType(),
                IsOpen = baseAccount.IsOpen
            });
        }
예제 #2
0
        /// <summary>
        /// Converts entity of <see cref="DalPerson"/> to <see cref="Person"/>
        /// </summary>
        /// <param name="person"> Entity for converting from <see cref="DalPerson"/> </param>
        /// <returns> Entity of  <see cref="Person"/> </returns>
        public static Person ToPerson(this DalPerson person)
        {
            if (person == null)
            {
                return(null);
            }

            return(new Person()
            {
                Id = person.Id,
                FirstName = person.FirstName,
                MiddleName = person.SecondName,
                LastName = person.LastName,
                Passport = new Passport
                {
                    PassportSeries = person.SerialNumber
                },
                ContactData = new ContactData
                {
                    Email = person.Contact.Email
                },
                Accounts = person.Accounts.ToAccounts(),
                IsDeleted = person.IsDeleted
            });
        }
예제 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection Connection =
                new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionBaseDatabase"].ConnectionString);

            Connection.Open();
            DalPerson = new DalPerson(Connection);
            LoadDataGridView(null);
        }
예제 #4
0
        /// <summary>
        /// Adds entity of the <see cref="DalPerson"/> class to context
        /// </summary>
        /// <param name="entity"> Entity for saving </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="entity"/> is null.
        /// </exception>
        public void Create(DalPerson entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            context.Set <Person>().Add(entity.ToPerson());
        }
예제 #5
0
        /// <summary>
        /// Removes entity of the <see cref="DalPerson"/> class from context
        /// </summary>
        /// <param name="entity"> Entity for removing </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="entity"/> is null.
        /// </exception>
        public void Delete(DalPerson entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var person = context.Set <Person>().Single(u => u.Id == entity.Id);

            person.IsDeleted = true;
        }
예제 #6
0
        /// <summary>
        /// Converts entity of <see cref="DalPerson"/> in <see cref="Person"/>
        /// </summary>
        /// <param name="person"> Entity for converting from <see cref="DalPerson"/> </param>
        /// <returns> Entity of  <see cref="Person"/> </returns>
        public static Person ToPerson(this DalPerson person)
        {
            if (person == null)
            {
                return(null);
            }

            return(new Person
            {
                FirstName = person.FirstName,
                LastName = person.LastName,
                SecondName = person.SecondName,
                SerialNumber = person.SerialNumber,
                Email = person.Contact.Email,
                Accounts = person.Accounts.ToAccounts().ToList(),
                IsDeleted = person.IsDeleted
            });
        }
예제 #7
0
        /// <summary>
        /// Updates person by values from entity of the <see cref="DalPerson"/> class
        /// </summary>
        /// <param name="entity">  Entity of the <see cref="DalPerson"/> class </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="entity"/> is null.
        /// </exception>
        public bool Update(DalPerson entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            Person entityToUpdate = context.Set <Person>().First(e => e.Id == entity.Id);

            if (entityToUpdate == null)
            {
                return(false);
            }

            try
            {
                context.Entry(entityToUpdate).CurrentValues.SetValues(entity.ToPerson());
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #8
0
        /// <summary>
        /// Converts entity of <see cref="Person"/> in <see cref="DalPerson"/>
        /// </summary>
        /// <param name="person"> Entity for converting from <see cref="Person"/> </param>
        /// <returns> Entity of  <see cref="DalPerson"/> </returns>
        public static DalPerson ToDalPerson(this Person person)
        {
            if (person == null)
            {
                return(null);
            }

            var dalPerson = new DalPerson
            {
                FirstName    = person.FirstName,
                LastName     = person.LastName,
                SecondName   = person.SecondName,
                SerialNumber = person.SerialNumber,
                Accounts     = person.Accounts.ToDalAccount().ToList(),
                IsDeleted    = person.IsDeleted
            };

            dalPerson.Contact = new DalContactData
            {
                Email = person.Email
            };

            return(dalPerson);
        }