Ejemplo n.º 1
0
        public virtual T Update(T t, object key)
        {
            if (t == null)
            {
                return(null);
            }
            T exist = _context.Set <T>().Find(key);

            if (exist != null)
            {
                _context.Entry(exist).CurrentValues.SetValues(t);
            }

            return(exist);
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutProsumption(int id, Prosumption prosumption)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != prosumption.ProsumptionId)
            {
                return(BadRequest());
            }

            db.Entry(prosumption).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutProsumerConsumption([FromRoute] long id, [FromBody] ProsumerConsumption prosumerConsumption)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(prosumerConsumption).State = EntityState.Modified;

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

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> PutProsumer(string id, double production, double consumption)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Prosumer prosumer = await db.Prosumers.FindAsync(id);

            if (prosumer == null)
            {
                return(BadRequest());
            }

            db.Entry(prosumer).State = EntityState.Modified;
            prosumer.Production      = production;
            prosumer.Consumption     = consumption;
            prosumer.Balance         = production - consumption;

            try
            {
                await _uow.ProsumerRepository.UpdateAsync(prosumer, id);

                await _uow.SaveAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProsumerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }