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