Пример #1
0
        public IHttpActionResult CreatePlc(PlcDto plcDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var plc = Mapper.Map <PlcDto, Plc>(plcDto);

            _context.Plcs.Add(plc);
            _context.SaveChanges();

            plcDto.Id = plc.Id;

            return(Created(new Uri(Request.RequestUri + "/" + plc.Id), plcDto));
        }
Пример #2
0
        public IHttpActionResult UpdatePlc(PlcDto plcDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var plcInDb = _context.Plcs.SingleOrDefault(p => p.Id == plcDto.Id);

            if (plcInDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(plcDto, plcInDb);

            _context.SaveChanges();

            return(Ok());
        }