コード例 #1
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());
        }
コード例 #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));
        }
コード例 #3
0
        public async Task <IHttpActionResult> DeleteProsumer(string id)
        {
            Prosumer prosumer = await db.Prosumers.FindAsync(id);

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

            Identity identity = await db.Identities.FindAsync(prosumer.IdentityId);

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

            db.Identities.Remove(identity);
            db.Prosumers.Remove(prosumer);
            await db.SaveChangesAsync();

            return(Ok(prosumer));
        }