public async Task <bool> UpdateToy(CreateToyViewModel model, int id)
        {
            bool isUpdated = false;

            Toy toy = await _context.Toys.FindAsync(id);

            if (model.Quantity < 0)
            {
                return(isUpdated);
            }


            if (toy != null)
            {
                _context.Entry(toy).State = EntityState.Detached;
                toy       = _mapper.Map <Toy>(model);
                toy.ToyId = id;
                _context.Entry(toy).State = EntityState.Modified;


                _context.Toys.Update(toy);

                var response = await _context.SaveChangesAsync();

                if (response == SystemStatusCode.SUCCESS)
                {
                    isUpdated = true;
                }
            }
            return(isUpdated);
        }
Beispiel #2
0
        public async Task <int> CreateNewToy(CreateToyViewModel model)
        {
            Toy toy = _mapper.Map <Toy>(model);

            toy.IsDeleted = false;

            int id = await _toy.CreateNewToy(toy);

            return(id);
        }
        public async Task <ActionResult> UpdateToy([FromBody] CreateToyViewModel model, int id)
        {
            bool isUpdated = await _toyService.UpdateToy(model, id);

            if (!isUpdated)
            {
                return(StatusCode(500));
            }
            else
            {
                return(StatusCode(200));
            }
        }
        public async Task <ActionResult <string> > CreateNewToy([FromBody] CreateToyViewModel model)
        {
            int id = await _toyService.CreateNewToy(model);

            if (id == SystemStatusCode.ERROR || id == SystemStatusCode.FAIL)
            {
                return(StatusCode(500));
            }
            else
            {
                var message = "toyId: " + id;
                return(StatusCode(201, message));
            }
        }
Beispiel #5
0
        public async Task <bool> UpdateToy(CreateToyViewModel model, int id)
        {
            bool isUpdated = await _toy.UpdateToy(model, id);

            return(isUpdated);
        }