Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PutStore(Store entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _dbContext.ApplyChanges(entity);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_dbContext.Stores.Any(e => e.StoreId == entity.StoreId))
                {
                    return(Conflict());
                }
                throw;
            }

            await _dbContext.LoadRelatedEntitiesAsync(entity);

            entity.AcceptChanges();
            return(Ok(entity));
        }
Ejemplo n.º 2
0
        public async Task<IHttpActionResult> PostStore(Store entity)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            entity.TrackingState = TrackingState.Added;
            _dbContext.ApplyChanges(entity);


            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (_dbContext.Stores.Any(e => e.StoreId == entity.StoreId))
                {
                    return Conflict();
                }
                throw;
            }

            await _dbContext.LoadRelatedEntitiesAsync(entity);
            entity.AcceptChanges();
            return CreatedAtRoute("DefaultApi", new { id = entity.StoreId }, entity);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PostStore(Store entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            entity.TrackingState = TrackingState.Added;
            _dbContext.ApplyChanges(entity);


            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (_dbContext.Stores.Any(e => e.StoreId == entity.StoreId))
                {
                    return(Conflict());
                }
                throw;
            }

            await _dbContext.LoadRelatedEntitiesAsync(entity);

            entity.AcceptChanges();
            return(CreatedAtRoute("DefaultApi", new { id = entity.StoreId }, entity));
        }
Ejemplo n.º 4
0
        public async Task<IHttpActionResult> PutStore(Store entity)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _dbContext.ApplyChanges(entity);

            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_dbContext.Stores.Any(e => e.StoreId == entity.StoreId))
                {
                    return Conflict();
                }
                throw;
            }

            await _dbContext.LoadRelatedEntitiesAsync(entity);
            entity.AcceptChanges();
            return Ok(entity);
        }