示例#1
0
        public bool Create(Object obj)
        {
            bool Created = true;

            try
            {
                _context.Connection.Execute(
                    "SP_NewObject",
                    new
                {
                    obj.Id,
                    obj.Title,
                    obj.Description,
                    obj.Creator,
                    obj.Father,
                    obj.Path,
                    obj.Type,
                    obj.Status,
                    obj.CreationDate
                },
                    commandType: CommandType.StoredProcedure);
            }
            catch (Exception e)
            {
                Created = false;
                AddNotification("Error", e.Message);

                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { Object = obj }, e);
            }

            return(Created);
        }
        public ICommandResult Handle(GetObjectCommand command)
        {
            ICommandResult result = new GetObjectCommandResult();

            _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Object, command.RequestHost }, "ObjectCommandHandler.Handle(Get)");

            try
            {
                if (_objectRepository.CheckExists(command.Object))
                {
                    Object obj = _objectRepository.Get(command.Object);

                    if (obj != null)
                    {
                        result = new GetObjectCommandResult(200, obj.Title, obj.Description, obj.Creator, obj.Father, obj.Path, obj.Type, obj.Status, obj.CreationDate);
                    }
                }

                else if (_objectRepository.Valid)
                {
                    result = new GetObjectCommandResult(400, new Notification("Object", "Could not be found"));
                }
            }
            catch (Exception e)
            {
                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Object, command.RequestHost }, e);
            }

            return(result);
        }
        public ICommandResult Handle(UpdateObjectCommand command)
        {
            ICommandResult result = new CommandResult();

            _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Id, command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status, command.RequestHost }, "ObjectCommandHandler.Handle(Update)");

            try
            {
                Object obj = new Object(command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status);

                if (obj.Valid)
                {
                    if (_objectRepository.CheckExists(command.Id))
                    {
                        if (!_objectRepository.CheckExists(obj.Title))
                        {
                            if (_objectRepository.Update(command.Id, obj))
                            {
                                result = new CommandResult(200);
                            }
                        }

                        else if (_objectRepository.Valid)
                        {
                            result = new CommandResult(400, new Notification("Title", "Already in Use"));
                        }
                    }

                    else if (_objectRepository.Valid)
                    {
                        result = new CommandResult(400, new Notification("Object", "Could not be found"));
                    }
                }

                else
                {
                    result = new NewObjectCommandResult(400, obj.Notifications);
                }
            }
            catch (Exception e)
            {
                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Id, command.Title, command.Description, command.Creator, command.Father, command.Path, command.Type, command.Status, command.RequestHost }, e);
            }

            return(result);
        }
示例#4
0
        public Object Get(Guid id)
        {
            Object obj = null;

            try
            {
                obj = _context.Connection.Query <Object>(
                    "SP_GetObject",
                    new
                    { Id = id },
                    commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            catch (Exception e)
            {
                AddNotification("Error", e.Message);

                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { Id = id }, e);
            }

            return(obj);
        }