public RoomsController(IRoomServices roomServices,
     IAccessoryServices accessoryServices,
     IUserServices userServices)
 {
     this.roomServices = roomServices;
     this.accessoryServices = accessoryServices;
     this.userServices = userServices;
 }
 public AccessoriesController(IAccessoryServices accessoryServices,
     IUserServices userServices)
 {
     this.accessoryServices = accessoryServices;
     this.userServices = userServices;
 }
        public int AddAccessoryToRoom(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)
                {
                    acs = new AccessoryServices();
                    int creationResult = acs.CreateAccessory(am);
                    if(creationResult == DaoUtilities.SAVE_SUCCESSFUL)
                    {
                        CONTAINSACCESSORY ca = db.CONTAINSACCESSORY.Create();
                        ca.ROOM_ID = RoomId;
                        ca.ACCESSORY_ID = am.AccessoryId;
                        ca.CONTAINS_QUANTITY = quantity;
                        r.CONTAINSACCESSORY.Add(ca);
                        a = db.ACCESSORY.Find(am.AccessoryId);
                        a.CONTAINSACCESSORY.Add(ca);
                    }
                }
                else
                {
                    CONTAINSACCESSORY ca = db.CONTAINSACCESSORY.Create();
                    ca.ROOM_ID = RoomId;
                    ca.ACCESSORY_ID = a.ACCESSORY_ID;
                    ca.CONTAINS_QUANTITY = quantity;
                    r.CONTAINSACCESSORY.Add(ca);
                    a.CONTAINSACCESSORY.Add(ca);
                }
                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;
        }