Ejemplo n.º 1
0
        internal static EnumServices.UpdateResult UpdateMember(Members member)
        {
            using (var db = new CorePracticeWebAppContext())
            {
                try
                {
                    var memberInDb = db.Members.Find(member.Id);
                    if (memberInDb != null)
                    {
                        memberInDb.City          = member.City;
                        memberInDb.Country       = member.Country;
                        memberInDb.DateofBap     = member.DateofBap;
                        memberInDb.DateOfBirth   = member.DateOfBirth;
                        memberInDb.FirstName     = member.FirstName;
                        memberInDb.LastName      = member.LastName;
                        memberInDb.State         = member.State;
                        memberInDb.StreetAddress = member.StreetAddress;
                        memberInDb.IsActive      = member.IsActive;

                        db.SaveChanges();
                    }
                    else
                    {
                        throw new KeyNotFoundException("Member not found");
                    }
                }
                catch (Exception e)
                {
                    return(EnumServices.UpdateResult.fail);
                }

                return(EnumServices.UpdateResult.success);
            }
        }
Ejemplo n.º 2
0
        internal static int AddMember(Members member)
        {
            using (var db = new CorePracticeWebAppContext())
            {
                try
                {
                    db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Members] ON");
                    db.Members.Add(member);
                    db.SaveChanges();
                    db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Members] OFF");
                }
                catch (Exception e)
                {
                }
            }

            return(member.Id);
        }