Пример #1
0
        public async Task <IHttpActionResult> PostEntity(EntityDTO value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                DbContext.Entities.Add(EntityTX.ReadFromDTO(new Entity(), value));
                await DbContext.SaveChangesAsync();

                return(CreatedAtRoute("DefaultApi", new { EntityId = value.EntityId }, value));
            }
            catch (Exception ex)
            {
                Log.Error("Entity.Post: " + ex);
                throw;
            }
        }
Пример #2
0
        public async Task <IHttpActionResult> GetEntity(int entityId)
        {
            try
            {
                EntityDTO found = await Task.Run(() =>
                {
                    return(EntityTX.WriteToDTO(DbContext.Entities
                                               .AsEnumerable().FirstOrDefault(e => e.EntityId == entityId)));
                });

                if (found == null)
                {
                    return(NotFound());
                }
                return(Ok(found));
            }
            catch (Exception ex)
            {
                Log.Error("Entity.Get: " + ex);
                throw;
            }
        }