示例#1
0
        public async Task <IActionResult> DeleteCommandToFunction(string functionId, [FromQuery] CommandAssignRequest request)
        {
            foreach (var commandId in request.CommandIds)
            {
                var entity = await _context.CommandInFunctions.FindAsync(commandId, functionId);

                if (entity == null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command is not existed in function")));
                }

                _context.CommandInFunctions.Remove(entity);
            }

            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Delete command to function failed")));
            }
        }
        public async Task <IActionResult> DeleteCommandToFunction(string functionId, [FromQuery] CommandAssignRequest request)
        {
            //// DELETE EACH COMMAND FROM THIS FUNCTION
            foreach (var commandId in request.CommandIds)
            {
                //// IF NOT EXSIST COMMAND ON FUNCTION, RETURN STATUS 400, ELSE REMOVE THAT COMMAND
                var entity = await _context.CommandInFunctions.FindAsync(commandId, functionId);

                if (entity == null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command is not existed in function")));
                }

                _context.CommandInFunctions.Remove(entity);
            }

            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Delete command to function failed")));
            }
        }
 public CommandAssignRequestValidatorTest()
 {
     request = new CommandAssignRequest()
     {
         AddToAllFunctions = true,
         CommandIds        = new string[] { "ADD" }
     };
     validator = new CommandAssignRequestValidator();
 }
示例#4
0
        public async Task <IActionResult> PostCommandToFunction(string functionId, [FromBody] CommandAssignRequest request)
        {
            //var commandInFunction = await _context.CommandInFunctions.FindAsync(request.CommandId, request.FunctionId);
            //if (commandInFunction != null)
            //    return BadRequest(new ApiBadRequestResponse($"This command has been added to function"));

            //var entity = new CommandInFunction()
            //{
            //    CommandId = request.CommandId,
            //    FunctionId = request.FunctionId
            //};
            foreach (var commandId in request.CommandIds)
            {
                if (await _context.CommandInFunctions.FindAsync(commandId, functionId) != null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command is not existed in function")));
                }
                var entity = new CommandInFunction()
                {
                    CommandId  = commandId,
                    FunctionId = functionId
                };

                _context.CommandInFunctions.Add(entity);
            }
            if (request.AddToAllFunctions)
            {
                var ortherFunction = _context.Functions.Where(x => x.Id != functionId);
                foreach (var function in ortherFunction)
                {
                    foreach (var commandId in request.CommandIds)
                    {
                        if (await _context.CommandInFunctions.FindAsync(commandId, functionId) == null)
                        {
                            _context.CommandInFunctions.Add(new CommandInFunction()
                            {
                                CommandId  = commandId,
                                FunctionId = function.Id
                            });
                        }
                    }
                }
            }
            var result = await _context.SaveChangesAsync();

            //_context.CommandInFunctions.Add(entity);

            if (result > 0)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Add command to function failed")));
            }
        }
        public async Task <IActionResult> PostCommandToFunction(string functionId, [FromBody] CommandAssignRequest request)
        {
            //// ADD EACH COMMAND TO FUNCTION
            foreach (var commandId in request.CommandIds)
            {
                //// IF EXIST COMAND IN THIS FUNCTION, RETURN STATSU 400
                if (await _context.CommandInFunctions.FindAsync(commandId, functionId) != null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command has been existed in function")));
                }

                //// ADD NEW COMMAND TO THIS FUNCTION
                var entity = new CommandInFunction()
                {
                    CommandId  = commandId,
                    FunctionId = functionId
                };

                _context.CommandInFunctions.Add(entity);
            }

            //// IF WANT ADD COMMAND FOR ALL FUNCTIONS
            if (request.AddToAllFunctions)
            {
                var otherFunctions = _context.Functions.Where(x => x.Id != functionId);
                foreach (var function in otherFunctions)
                {
                    foreach (var commandId in request.CommandIds)
                    {
                        if (await _context.CommandInFunctions.FindAsync(request.CommandIds, function.Id) == null)
                        {
                            _context.CommandInFunctions.Add(new CommandInFunction()
                            {
                                CommandId  = commandId,
                                FunctionId = function.Id
                            });
                        }
                    }
                }
            }

            //// ADD COMMANDS AND SAVE CHANGES
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(CreatedAtAction(nameof(GetById), new { request.CommandIds, functionId }));
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Add command to function failed")));
            }
        }
示例#6
0
        public async Task <IActionResult> PostCommandToFunction(string functionId, [FromBody] CommandAssignRequest request)
        {
            foreach (var commandId in request.CommandIds)
            {
                if (await _context.CommandInFunctions.FindAsync(commandId, functionId) != null)
                {
                    return(BadRequest(new ApiBadRequestResponse("This command has been existed in function")));
                }

                var entity = new CommandInFunction()
                {
                    CommandId  = commandId,
                    FunctionId = functionId
                };

                _context.CommandInFunctions.Add(entity);
            }

            if (request.AddToAllFunctions)
            {
                var otherFunctions = _context.Functions.Where(x => x.Id != functionId);
                foreach (var function in otherFunctions)
                {
                    foreach (var commandId in request.CommandIds)
                    {
                        if (await _context.CommandInFunctions.FindAsync(request.CommandIds, function.Id) == null)
                        {
                            _context.CommandInFunctions.Add(new CommandInFunction()
                            {
                                CommandId  = commandId,
                                FunctionId = function.Id
                            });
                        }
                    }
                }
            }
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(CreatedAtAction(nameof(GetById), new { request.CommandIds, functionId }));
            }
            else
            {
                return(BadRequest(new ApiBadRequestResponse("Add command to function failed")));
            }
        }
示例#7
0
        public async Task <IActionResult> DeleteCommandToFunction(string functionId, [FromQuery] CommandAssignRequest request)
        {
            foreach (var commandId in request.CommandIds)
            {
                var entity = await _context.CommandInFunctions.FindAsync(commandId, functionId);

                if (entity == null)
                {
                    return(BadRequest(new ApiBadRequestResponse(_localizer["CommandExisted"])));
                }

                _context.CommandInFunctions.Remove(entity);
            }

            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                return(Ok());
            }

            return(BadRequest(new ApiBadRequestResponse(_localizer["DeleteCommandFail"])));
        }
示例#8
0
 public string DeleteCommandToFunction(string funcId, CommandAssignRequest request)
 {
     throw new NotImplementedException();
 }