Exemple #1
0
        // ---------------------------------------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public OperationResult UpdateReservable(DTOReservable tableDTO)
        {
            OperationResult result = new OperationResult();

            //::::::::::::::::::::::::::::::::::::::::::

            using (TransactionScope scope = new TransactionScope(TransactionMode.New, OnDispose.Commit))
            {
                try
                {
                    Table    tableToUpdate = Table.Find(tableDTO.Id);
                    Location location      = Location.Find(tableToUpdate.ParentLocation.Id);

                    location.UpdateTable(tableToUpdate, tableDTO.Name, tableDTO.MaxGuests, tableDTO.X, tableDTO.Y, tableDTO.Width, tableDTO.Height, tableDTO.Shape, tableDTO.Number);

                    result.Success        = true;
                    result.ObjectAffected = tableDTO.Id;
                    result.Message        = string.Format("Table id => {0} update ok", tableDTO.Id);

                    ServiceLogger.Log(result.Message);
                }
                catch (ReservableAlreadyExistsException rae)
                {
                    scope.VoteRollBack();

                    // TODO: logging, proper message in result

                    result.Success        = false;
                    result.ObjectAffected = 0;
                    result.Message        = rae.ToString();

                    ServiceLogger.LogException(string.Format("Table already exists => {0}.", tableDTO.ToString()), rae);
                }
                catch (Castle.ActiveRecord.NotFoundException nfe)
                {
                    scope.VoteRollBack();
                    // TODO: logging, proper message in result
                    result.Success        = false;
                    result.ObjectAffected = 0;
                    result.Message        = nfe.ToString();

                    ServiceLogger.LogException(string.Format("Table not found => {0}.", tableDTO.ToString()), nfe);
                }
                catch (ActiveRecordException are)
                {
                    scope.VoteRollBack();
                    // TODO: logging, proper message in result
                    result.Success        = false;
                    result.ObjectAffected = 0;
                    result.Message        = are.ToString();

                    ServiceLogger.LogException(string.Format("Table => {0}.", tableDTO.ToString()), are);
                }
            }

            //::::::::::::::::::::::::::::::::::::::::::

            return(result);
        }
Exemple #2
0
        // ---------------------------------------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public OperationResult DeleteReservable(DTOReservable tableDTO, DTOLocation locationDTO)
        {
            OperationResult result = new OperationResult();

            //::::::::::::::::::::::::::::::::::::::::::

            using (TransactionScope txnScope = new TransactionScope(TransactionMode.New, OnDispose.Commit))
            {
                try
                {
                    Table table = Table.Find(tableDTO.Id);

                    // remove the reference to the table from the location
                    Location loc = Location.Find(locationDTO.Id);
                    loc.RemoveTable(table);

                    result.Success        = true;
                    result.Message        = string.Format("Table => {0} deleted ok.", tableDTO.Name);
                    result.ObjectAffected = tableDTO.Id;

                    ServiceLogger.Log(result.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    txnScope.VoteRollBack();
                    result.Success        = false;
                    result.Message        = string.Format("Cannot delete table => {0}{1}{2}.", tableDTO.ToString(), Environment.NewLine, ioe.ToString());
                    result.ObjectAffected = tableDTO.Id;

                    ServiceLogger.LogException(string.Format("Cannot delete table => {0}.", tableDTO.ToString()), ioe);
                }
                catch (ActiveRecordException are)
                {
                    txnScope.VoteRollBack();

                    result.Success        = false;
                    result.Message        = string.Format("Error when trying to delete Table => {0};{1}{2}", tableDTO.Name, Environment.NewLine, are.ToString());
                    result.ObjectAffected = tableDTO.Id;

                    ServiceLogger.LogException(string.Format("Error when trying to delete Table => {0}", tableDTO.Name), are);
                }
            }

            //::::::::::::::::::::::::::::::::::::::::::

            return(result);
        }
Exemple #3
0
        // ---------------------------------------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public OperationResult AddReservable(DTOReservable tableDTO, DTOLocation locationDTO)
        {
            OperationResult result = new OperationResult();

            //::::::::::::::::::::::::::::::::::::::::::

            using (TransactionScope scope = new TransactionScope(TransactionMode.New, OnDispose.Commit))
            {
                try
                {
                    DTOHelpers.ValidateReservableDTO(tableDTO);
                    DTOHelpers.ValidateLocationDTO(locationDTO);

                    Location location = Location.Find(locationDTO.Id);
                    Table    table    = DTOHelpers.TableFromDTO(tableDTO);

                    location.AddTable(table);

                    result.Success        = true;
                    result.ObjectAffected = table.Id;
                    result.Message        = String.Format("{0} added successfully to {1}", tableDTO.ToString(), location.ToString());

                    ServiceLogger.Log(string.Format("Table {0} added to location {1}", tableDTO.Name, location.Name));
                }
                catch (ActiveRecordException are)
                {
                    scope.VoteRollBack();
                    result.Success = false;
                    result.Message = string.Format("Could not add table {0};{1}{2}", tableDTO.Name, Environment.NewLine, are.ToString());

                    ServiceLogger.LogException(string.Format("Could not add table {0}", tableDTO.Name), are);
                }
                catch (ReservableAlreadyExistsException rree)
                {
                    scope.VoteRollBack();
                    result.Success = false;
                    result.Message = string.Format("A table called => {0} already exists;{1}{2}", tableDTO.Name, Environment.NewLine, rree.ToString());

                    ServiceLogger.LogException(string.Format("A table called => {0} already exists", tableDTO.Name), rree);
                }
                catch (InvalidDTOException ide)
                {
                    scope.VoteRollBack();
                    result.Success = false;
                    result.Message = string.Format("Problem with supplied information, cannot add table {0}; {1}{2}", tableDTO.Name, Environment.NewLine, ide.ToString());

                    ServiceLogger.LogException(string.Format("Problem with supplied information, cannot add table {0}", tableDTO.Name), ide);
                }
            }

            //::::::::::::::::::::::::::::::::::::::::::

            return(result);
        }