Ejemplo n.º 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();
        }
 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));
     }
 }
Ejemplo n.º 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());
        }
        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));
            }
        }
        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));
            }
        }