public async Task <DictionaryCrudResponse> DirectionCrud(DictionaryCrudRequest input)
        {
            var data = input.Direction;

            if (data == null && input.IdToDelete == null)
            {
                throw new ValidationException("Не распарсилось");
            }

            var sqlR = new DirectionsRepository(_logger);

            if (input?.IdToDelete != null)
            {
                await sqlR.Delete((int)input.IdToDelete);

                return(new DictionaryCrudResponse {
                    IsDeleted = true, Direction = data
                });
            }

            var all = await sqlR.GetAll();

            if (all.Any(x => x.Name.Equals(input.Direction.Name)))
            {
                throw new ValidationException(Error.AlreadyAddWithThisName);
            }

            if (data?.Id == 0)
            {
                var item = await sqlR.Add(data);

                return(new DictionaryCrudResponse {
                    IsAdd = true, Direction = item
                });
            }
            else
            {
                var item = await sqlR.Update(data);

                return(new DictionaryCrudResponse {
                    IsUpdated = true, Direction = item
                });
            }
        }
Esempio n. 2
0
        public async Task Delete(int id)
        {
            await CheckPermission();

            await _sqlR.Delete(id);
        }