Ejemplo n.º 1
0
        /// <summary>
        /// Update an existing Guest in the databse.
        /// </summary>
        /// <param name="p_guest">New Guest-Object.</param>
        /// <returns>The updated Guest-Object. NULL, or Exception if an error occurs.</returns>
        public Guest Update(Guest p_guest)
        {
            using (var context = new FhdwHotelContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        p_guest.ContactAddress = context.Address.SingleOrDefault(a => a.ID == p_guest.ContactAddress.ID);
                        p_guest.BillingAddress = context.Address.SingleOrDefault(a => a.ID == p_guest.BillingAddress.ID);

                        context.Guest.Add(p_guest);
                        context.SaveChanges();
                        transaction.Commit();

                        return p_guest;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        transaction.Rollback();
                        return null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add, or Update a Guest.
        /// </summary>
        /// <param name="p_guest">Guestobject</param>
        /// <returns>Updated, or added Guest.</returns>
        public Guest SaveGuest(Guest p_guest)
        {
            if (p_guest == null) return null;

            p_guest.Password = Convert.ToBase64String(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(p_guest.Password)));
            return p_guest.ID == 0 ? _guestRepository.Insert(p_guest) : _guestRepository.Update(p_guest);
        }