コード例 #1
0
        public void Update(MyData dbEntity, MyDataModel entity)
        {
            dbEntity.id          = Guid.Parse(entity.id);
            dbEntity.name        = entity.name;
            dbEntity.description = entity.description;
            dbEntity.amount      = entity.amount;
            dbEntity.date        = entity.date.Ticks;
            dbEntity.isPrivate   = entity.isPrivate;

            _upstartTestContext.SaveChanges();
        }
コード例 #2
0
 public IActionResult GetData(string id)
 {
     try
     {
         MyDataModel myData = _dataRepository.Get(id);
         return(Ok(myData));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
コード例 #3
0
        public string Add(MyDataModel entity)
        {
            MyData dbEntity = new MyData();

            dbEntity.name        = entity.name;
            dbEntity.description = entity.description;
            dbEntity.amount      = entity.amount;
            dbEntity.date        = entity.date.Ticks;
            dbEntity.isPrivate   = entity.isPrivate;

            _upstartTestContext.MyDatas.Add(dbEntity);
            _upstartTestContext.SaveChanges();

            return(dbEntity.id.ToString());
        }
コード例 #4
0
        public IActionResult Post(MyDataModel myData)
        {
            if (myData == null)
            {
                return(BadRequest("Data is null."));
            }

            try
            {
                myData.id = _dataRepository.Add(myData);
                return(CreatedAtRoute("GetData", new { id = myData.id }, myData));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
コード例 #5
0
        public IActionResult Put(string id, MyDataModel myData)
        {
            myData.id = id;
            if (myData == null)
            {
                return(BadRequest("data is null."));
            }

            MyData dataToUpdate = _dataRepository.GetToUpdate(id);

            try
            {
                _dataRepository.Update(dataToUpdate, myData);
                return(CreatedAtRoute("GetData", new { id = myData.id }, myData));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }