예제 #1
0
        public async Task <IHttpActionResult> PostSalesPerson(SalesPersonDTO value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                DbContext.SalesPersons.Add(SalesPersonTX.ReadFromDTO(new SalesPerson(), value));
                await DbContext.SaveChangesAsync();

                return(CreatedAtRoute("DefaultApi", new { EntityId = value.EntityId }, value));
            }
            catch (Exception ex)
            {
                Log.Error("SalesPerson.Post: " + ex);
                throw;
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> GetSalesPerson(int entityId)
        {
            try
            {
                SalesPersonDTO found = await Task.Run(() =>
                {
                    return(SalesPersonTX.WriteToDTO(DbContext.SalesPersons
                                                    .AsEnumerable().FirstOrDefault(e => e.EntityId == entityId)));
                });

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