Ejemplo n.º 1
0
        public async Task <IActionResult> PutDrug([FromRoute] int id, [FromBody] Drug drug)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != drug.Id)
            {
                return(BadRequest());
            }

            _drugRepository.Update(drug);

            try
            {
                await _drugRepository.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_drugRepository.DrugExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateDrug([FromBody] DrugDTO drugDTO)
        {
            if (drugDTO == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var itExists = await _drugRepository.ItExists(drugDTO.Id);

            if (!itExists)
            {
                return(NotFound());
            }

            var drug = _mapper.Map <Drug>(drugDTO);

            var isSuccess = await _drugRepository.Update(drug);

            if (!isSuccess)
            {
                return(InternalError($"Update operation failed"));
            }

            return(NoContent()); //success
        }
Ejemplo n.º 3
0
        public IActionResult Edit(EditDrug drugs)
        {
            if (ModelState.IsValid)
            {
                Drugs drug = _drugRepository.GetDrugsbyId(drugs.Id);
                drug.Name        = drugs.Name;
                drug.Description = drugs.Description;


                _drugRepository.Update(drug);
                return(RedirectToAction("CreateByStore", "Drugs", new
                {
                    Id = drug.StoresId
                }));
                //return RedirectToAction("CreateByStore");
            }
            return(View());
        }