예제 #1
0
        public async Task <InformCostType> AddInformCostType(InformCostType costType)
        {
            var result = await _context.InformCostTypes.AddAsync(costType);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
예제 #2
0
        public async Task <InformCostType> UpdateInformCostType(InformCostType costType)
        {
            var result = await _context.InformCostTypes.FirstOrDefaultAsync(s => s.Id == costType.Id);

            if (result != null)
            {
                result.CostType = costType.CostType;
                await _context.SaveChangesAsync();

                return(result);
            }

            return(null);
        }
예제 #3
0
        public async Task <ActionResult <InformCostType> > CreateInformCostType(InformCostType informCostType)
        {
            try
            {
                if (informCostType == null)
                {
                    return(BadRequest());
                }

                var createdInformCostType = await _informCostTypeRepository.AddInformCostType(informCostType);

                return(createdInformCostType);
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database."));
            }
        }
예제 #4
0
 public async Task UpdateInformCostType(int id, InformCostType type)
 {
     await httpClient.PutAsJsonAsync($"/api/informCostType/{id}", type);
 }
예제 #5
0
        public async Task <InformCostType> CreateInformCostType(InformCostType type)
        {
            var result = await httpClient.PostAsJsonAsync("/api/informCostTypes", type);

            return(await result.Content.ReadAsAsync <InformCostType>());
        }
예제 #6
0
        public async Task <ActionResult <InformCostType> > UpdateInformCostType(int id, InformCostType informCostType)
        {
            try
            {
                if (id != informCostType.Id)
                {
                    return(BadRequest());
                }

                var informCostTypeToUpdate = await _informCostTypeRepository.GetInformCostType(id);

                if (informCostTypeToUpdate == null)
                {
                    return(NotFound($"InformCostType with id = {id} not found"));
                }

                return(await _informCostTypeRepository.UpdateInformCostType(informCostType));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database."));
            }
        }