コード例 #1
0
        public async Task <int> Insert(CalculatedTime model)
        {
            try
            {
                _connection = Connect.Open();
                var p = new DynamicParameters();

                p.Add("@TimeTypeId", model.TimeTypeId);
                p.Add("@Value", model.Value);
                p.Add("@DailyTimeRecordId", model.DateTimeRecordId);
                p.Add("@CalculatedId", dbType: DbType.Int32, direction: ParameterDirection.Output);

                await _connection.ExecuteAsync("CalculatedTimeInsert", commandType : CommandType.StoredProcedure);

                return(p.Get <int>("@CalculatedId"));
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                _connection.Close();
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> PostCalculatedTime([FromBody] CalculatedTime model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = await _repository.Insert(model);

            string uri = Url.Link("hrdapi", new { id });

            return(Created(uri, model.TimeTypeId = id));
        }
コード例 #3
0
        public async Task <IHttpActionResult> PutCalculatedTime([FromBody] CalculatedTime model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _repository.SelectById(model.CalculatedTimeId);

            if (result == null)
            {
                return(NotFound());
            }

            await _repository.Update(model);

            return(Ok(model));
        }
コード例 #4
0
        public async Task Update(CalculatedTime model)
        {
            try
            {
                _connection = Connect.Open();
                var p = new DynamicParameters();

                p.Add("@CalculatedTimeId", model.CalculatedTimeId);
                p.Add("@TimeTypeId", model.TimeTypeId);
                p.Add("@Value", model.Value);
                p.Add("@DailyTimeRecordId", model.DateTimeRecordId);

                await _connection.ExecuteAsync("CalculatedTimeUpdate", p, commandType : CommandType.StoredProcedure);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                _connection.Close();
            }
        }