private string SqlAdd(TechPass input)
 {
     return($@"
         insert into {_table}
         (Number, PlaceDrawUp, DateDrawUp, TrainId)
         VALUES
         ({input.Number},'{input.PlaceDrawUp}', '{input.DateDrawUp}', {input.TrainId})
         SELECT SCOPE_IDENTITY()
     ");
 }
        public async Task <JsonResult> AddOrUpdate([FromBody] TechPass input)
        {
            await CheckPermission();

            if (input.Id != 0)
            {
                return(Json(await _techPassRepository.Update(input)));
            }
            return(Json(await _techPassRepository.Add(input)));
        }
 private string SqlUpdate(TechPass input)
 {
     return($@"
         update {_table}
         set
         Number = {input.Number},
         PlaceDrawUp = '{input.PlaceDrawUp}',
         DateDrawUp = '{input.DateDrawUp}',
         TrainId = {input.TrainId}
     ");
 }
        public async Task <TechPass> Add(TechPass input)
        {
            //var all = await GetAll();
            //if (all.Any(x => x.Name.Equals(input.Name)))
            //    throw new ValidationException(Error.AlreadyAddWithThisName);
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                var id = await conn.QueryFirstOrDefaultAsync <int>(SqlAdd(input));

                return(await ById(id));
            }
        }
        public async Task <TechPass> Update(TechPass input)
        {
            //var current = await ById(input.Id);
            //if (current.Name.Equals(input.Name))
            //    throw new ValidationException(Error.AlreadyAddWithThisName);

            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                await conn.ExecuteAsync(SqlUpdate(input));

                return(await ById(input.Id));
            }
        }