Exemplo n.º 1
0
        public async Task <IActionResult> UpdateLinkpool(int id, [FromBody] LinkpoolViewModel entity)
        {
            if (ModelState.IsValid)
            {
                if (entity == null)
                {
                    return(BadRequest($"{nameof(entity)} cannot be found"));
                }
                if (id != entity.LinkpoolId)
                {
                    return(BadRequest("Conflicting device id in parameter"));
                }

                var device = _unitOfWork.Linkpools.Get(id);
                if (device == null)
                {
                    return(NotFound());
                }
#if DEBUG
                Debug.WriteLine("UpdateDevice entity.LastUpdate = " + entity.LinkPath.ToString());
#endif

                _mapper.Map <LinkpoolViewModel, Linkpool>(entity, device);
                _unitOfWork.Linkpools.Update(device);
                _unitOfWork.SaveChanges();
                return(NoContent());
            }

            return(BadRequest(ModelState));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> NewLinkpool([FromBody] LinkpoolViewModel item)
        {
            if (ModelState.IsValid)
            {
                if (item == null)
                {
                    return(BadRequest($"{nameof(item)} cannot be found"));
                }
                var linkpool = _mapper.Map <Linkpool>(item);
                _unitOfWork.Linkpools.Add(linkpool);
                _unitOfWork.SaveChanges();

                var newItem = _unitOfWork.Linkpools.GetAll().OrderByDescending(o => o.LinkpoolId).FirstOrDefault();
                return(Ok(_mapper.Map <LinkpoolViewModel>(newItem)));
            }
            return(BadRequest(ModelState));
        }