public int DeleteAccessory(AccessoryModel am)
        {
            int result = DaoUtilities.NO_CHANGES;

            ACCESSORY a = db.ACCESSORY.Find(am.AccessoryId);

            if (a != null)
            {
                db.ACCESSORY.Remove(a);
                try
                {
                    int saveResult = db.SaveChanges();

                    if (saveResult == 1)
                        result = DaoUtilities.SAVE_SUCCESSFUL;
                }
                catch (DbUpdateConcurrencyException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION;
                }
                catch (DbUpdateException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UPDATE_EXCEPTION;
                }
                catch (DbEntityValidationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION;
                }
                catch (NotSupportedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.UNSUPPORTED_EXCEPTION;
                }
                catch (ObjectDisposedException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.DISPOSED_EXCEPTION;
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.GetBaseException().ToString());
                    result = DaoUtilities.INVALID_OPERATION_EXCEPTION;
                }
            }

            return result;
        }
        /// <summary>
        /// Convert an accessory from the database to an AccessoryModel
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public AccessoryModel ConvertAccesoryToAccessoryModel(ACCESSORY a)
        {
            AccessoryModel am = new AccessoryModel();

            if (a != null)
            {
                am.AccessoryId = a.ACCESSORY_ID;
                am.Name = a.ACCESSORY_NAME;
                am.Quantity = a.ACCESSORY_QUANTITY;
            }
            else
                am = null;

            return am;
        }
예제 #3
0
        public int UpdateAccessoryInRoom(string RoomId, AccessoryModel am, Nullable<decimal> quantity)
        {
            int result = DaoUtilities.NO_CHANGES;

            ROOM r = db.ROOM.Find(RoomId);

            if (r != null)
            {
                ACCESSORY a = db.ACCESSORY.Find(am.AccessoryId);
                if (a != null)
                {
                    CONTAINSACCESSORY ca = db.CONTAINSACCESSORY.Find(RoomId, am.AccessoryId);

                    if(ca != null)
                    {
                        ca.CONTAINS_QUANTITY = quantity;

                        try
                        {
                            int saveResult = db.SaveChanges();

                            if (saveResult == 1)
                                result = DaoUtilities.SAVE_SUCCESSFUL;
                        }
                        catch (DbUpdateConcurrencyException e)
                        {
                            Console.WriteLine(e.GetBaseException().ToString());
                            result = DaoUtilities.UPDATE_CONCURRENCY_EXCEPTION;
                        }
                        catch (DbUpdateException e)
                        {
                            Console.WriteLine(e.GetBaseException().ToString());
                            result = DaoUtilities.UPDATE_EXCEPTION;
                        }
                        catch (DbEntityValidationException e)
                        {
                            Console.WriteLine(e.GetBaseException().ToString());
                            result = DaoUtilities.ENTITY_VALIDATION_EXCEPTION;
                        }
                        catch (NotSupportedException e)
                        {
                            Console.WriteLine(e.GetBaseException().ToString());
                            result = DaoUtilities.UNSUPPORTED_EXCEPTION;
                        }
                        catch (ObjectDisposedException e)
                        {
                            Console.WriteLine(e.GetBaseException().ToString());
                            result = DaoUtilities.DISPOSED_EXCEPTION;
                        }
                        catch (InvalidOperationException e)
                        {
                            Console.WriteLine(e.GetBaseException().ToString());
                            result = DaoUtilities.INVALID_OPERATION_EXCEPTION;
                        }
                    }
                }
            }
            return result;
        }