public void CopyFrom(Location location) { //Id = location.Id; EntityId = location.EntityId; Name = location.Name; Description = location.Description; Items = new List<Guid>(); foreach (var item in location.Items) { Items.Add(item.EntityId); } }
public HttpResponseMessage Post([FromBody] LocationViewModel locationViewModel) { using (var db = new DBUnitOfWork()) { try { Location location = new Location(); location.CopyFrom(locationViewModel,db); db.Repository<Location>().Add(location); return Request.CreateResponse(HttpStatusCode.Created); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } } }
public HttpResponseMessage Put([FromODataUri] string key, [FromBody] LocationViewModel locationViewModel) { using (var db = new DBUnitOfWork()) { try { Location location = new Location(); location.CopyFrom(locationViewModel, db); location.EntityId = new Guid(key); if (db.Repository<Location>().Update(location, location.EntityId) != null) return Request.CreateResponse(HttpStatusCode.OK); else return Request.CreateResponse(HttpStatusCode.NoContent); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } } }