public void Insert(GivenResource r)
 {
     db.GivenResources.Add(r);
     db.SaveChanges();
 }
        public ActionResult Edit(ResourceViewModelsEdit resourcesEdit)
        {
            foreach (var item in resourcesEdit.Resources)
            {
                if (ModelState.IsValid)
                {
                    int handedOut = (int)(item.resource.NumberAvailable) - item.count;
                    int newStock = item.count;
                    //this if block allows the user to enter a negative number to indicate
                    //number handed out instead of current stock
                    if (item.count < 0)
                    {
                        handedOut = -item.count;
                        if((int)(item.resource.NumberAvailable) - handedOut < 0)
                            handedOut = (int)(item.resource.NumberAvailable);
                        newStock = (int)(item.resource.NumberAvailable) - handedOut;

                    }

                    CenterFreeResource aResource =  repoService.centerResourcesRepo.FindById(item.resource.Id);
                    aResource.NumberAvailable = newStock;
                    repoService.centerResourcesRepo.Update(aResource);
                    if (handedOut > 0)
                    {
                        GivenResource gr = new GivenResource();
                        gr.Count = handedOut;
                        gr.CenterFreeResourceId = item.resource.Id;
                        repoService.centerResourcesRepo.Insert(gr);
                    }
                }
            }
            return RedirectToAction("Index");
        }