Beispiel #1
0
        public async Task <JsonResult> Add([FromBody] Stantion input)
        {
            await CheckPermission();

            if (string.IsNullOrEmpty(input.Description) || string.IsNullOrEmpty(input.Name) || string.IsNullOrEmpty(input.StantionType.ToString()))
            {
                throw new Exception("Some input parameters NULL");
            }
            var sqlr = new StantionsRepository(_logger);

            try
            {
                if (input.Id != 0)
                {
                    await sqlr.Update(input);
                }
                else
                {
                    await sqlr.Add(input);
                }
                return(Json(new { message = "addOrUpdate OK" }));
            }
            catch (Exception e)
            {
                throw new Exception($"Can't add or update {this.GetType().ToString()} ex = {e}");
            }
        }
Beispiel #2
0
        public async Task <JsonResult> Delete([FromBody] Stantion stantion)
        {
            await CheckPermission();

            var cer = new StantionsRepository(_logger);
            await cer.Delete(stantion.Id);

            return(Json(new { message = "Delete OK" }));
        }
Beispiel #3
0
        public async Task <Stantion> Add(Stantion stantion)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                var resultId = await conn.QueryFirstOrDefaultAsync <int>(Sql.SqlQueryCach["Stantion.Add"],
                                                                         new { name = stantion.Name, description = stantion.Description, type = (int)stantion.StantionType });

                return(await ById(resultId));
            }
        }
Beispiel #4
0
        public async Task <Stantion> Update(Stantion stantion)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                if ((await ById(stantion.Id)) == null)
                {
                    throw new ValidationException("Нет станции с данным Id");
                }

                await conn.ExecuteAsync(Sql.SqlQueryCach["Stantion.Update"],
                                        new
                {
                    name        = stantion.Name,
                    description = stantion.Description,
                    type        = (int)stantion.StantionType,
                    id          = stantion.Id
                });

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