コード例 #1
0
 public IHttpActionResult Save([FromBody] Cost cost)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (cost.Id == 0)
     {
         costRepository.Add(cost);
     }
     else
     {
         var task = costRepository.GetById(cost.Id);
         if (task != null)
         {
             task.Name          = cost.Name;
             task.Priority      = cost.Priority;
             task.Description   = cost.Description;
             task.EstimatedCost = cost.EstimatedCost;
             costRepository.Update(task);
         }
     }
     unitOfWork.Commit();
     return(Ok(cost));
 }
コード例 #2
0
        public async Task <IActionResult> CreateCost(CostDTO costDTO)
        {
            var cost = _mapper.Map <CostDTO, Cost>(costDTO);
            await _costRepository.Add(cost);

            return(CreatedAtAction(nameof(GetCost), new { id = cost.CostId }, cost));
        }