Пример #1
0
        public void Update(DonorModel donor)
        {
            if (!UpdateDatabase)
            {
                var target = One(e => e.DonorID == donor.DonorID);

                if (target != null)
                {
                    target.DonorID      = donor.DonorID;
                    target.DonorName    = donor.DonorName;
                    target.Amount       = donor.Amount;
                    target.Phone        = donor.Phone;
                    target.CreateDate   = donor.CreateDate;
                    target.Address1     = donor.Address1;
                    target.Address2     = donor.Address2;
                    target.City         = donor.City;
                    target.DonorState   = donor.DonorState;
                    target.Zip          = donor.Zip;
                    target.BusinessName = donor.BusinessName;
                    target.FirstName    = donor.FirstName;
                    target.LastName     = donor.LastName;
                    target.Title        = donor.Title;
                    target.Notes        = donor.Notes;
                    target.Email        = donor.Email;
                }
            }
            else
            {
                var entity = new Donor();

                entity.DonorID      = donor.DonorID;
                entity.DonorName    = donor.DonorName;
                entity.Amount       = donor.Amount;
                entity.Phone        = donor.Phone;
                entity.CreateDate   = donor.CreateDate;
                entity.Address1     = donor.Address1;
                entity.Address2     = donor.Address2;
                entity.City         = donor.City;
                entity.State        = donor.DonorState;
                entity.Zip          = donor.Zip;
                entity.BusinessName = donor.BusinessName;
                entity.FirstName    = donor.FirstName;
                entity.LastName     = donor.LastName;
                entity.Title        = donor.Title;
                entity.Notes        = donor.Notes;
                entity.Email        = donor.Email;


                entities.Donors.Attach(entity);
                entities.Entry(entity).State = EntityState.Modified;
                entities.SaveChanges();
            }
        }
Пример #2
0
        public void Create(DonorModel donor)
        {
            if (!UpdateDatabase)
            {
                var first = GetAll().OrderByDescending(e => e.DonorID).FirstOrDefault();
                var id    = (first != null) ? first.DonorID : 0;

                GetAll().Insert(0, donor);
            }
            else
            {
                var entity = new Donor();

                entity.DonorID      = donor.DonorID;
                entity.DonorName    = donor.DonorName;
                entity.Amount       = donor.Amount;
                entity.Phone        = donor.Phone;
                entity.CreateDate   = donor.CreateDate;
                entity.Address1     = donor.Address1;
                entity.Address2     = donor.Address2;
                entity.City         = donor.City;
                entity.State        = donor.DonorState;
                entity.Zip          = donor.Zip;
                entity.BusinessName = donor.BusinessName;
                entity.FirstName    = donor.FirstName;
                entity.LastName     = donor.LastName;
                entity.Title        = donor.Title;
                entity.Notes        = donor.Notes;
                entity.Email        = donor.Email;

                entities.Donors.Add(entity);
                entities.SaveChanges();

                donor.DonorID = entity.DonorID;
            }
        }
Пример #3
0
        public void Destroy(DonorModel donor)
        {
            if (!UpdateDatabase)
            {
                var target = GetAll().FirstOrDefault(p => p.DonorID == donor.DonorID);
                if (target != null)
                {
                    GetAll().Remove(target);
                }
            }
            else
            {
                var target = (from s in entities.Donors
                              where s.DonorID == donor.DonorID
                              select s).FirstOrDefault();

                if (target != null)
                {
                    target.IsDeleted             = true;
                    entities.Entry(target).State = System.Data.Entity.EntityState.Modified;
                    entities.SaveChanges();
                }
            }
        }