예제 #1
0
 public static Opportunity NewOpportunity(Grant grant, string name, string description, int? numOfAward, long? totalAward, DateTime startDate, DateTime deadline)
 {
     return new Opportunity()
     {
         Id = Guid.NewGuid(),
         Grant = grant,
         Name = name,
         Description = description,
         NumberOfAward = numOfAward,
         TotalAward = totalAward,
         StartDate = startDate,
         Deadline = deadline
     };
 }
예제 #2
0
        public ActionResult Create(Grant grant)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    var agengy = _uow.Organizations.FindById(grant.AgencyId);
                    grant.Agency = (FundingAgency)agengy;
                    _svc.CreateGrant(grant);
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
예제 #3
0
 public void CreateGrant(Grant grant)
 {
     grant.Created = DateTime.UtcNow;
     _uow.GrantRepo.Add(grant);
     _uow.Commit();
 }
예제 #4
0
 public void PutGrantById(Guid id, Grant grant)
 {
     var item = _uow.GrantRepo.FindById(id);
     item.Code = grant.Code;
     item.Name = grant.Name;
     item.Description = grant.Description;
     item.Objective = grant.Objective;
     item.MaxAward = grant.MaxAward;
     item.MaxDuration = grant.MaxDuration;
     item.AgencyId = grant.AgencyId;
     item.Total = grant.Total;
     item.LastUpdated = DateTime.UtcNow;
     _uow.Commit();
 }
예제 #5
0
 public ActionResult Edit(Guid id, Grant grant)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             _svc.PutGrantById(id, grant);
         }
         var agencies = _svc.GetAllOrganizations();
         //var vm = new GrantBindingModel(grant, agencies);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
예제 #6
0
        //[Route("api/grants/{id}/budgets")]
        //public IHttpActionResult GetBudgets(Guid id)
        //{
        //    var grant = _uow.Grants.GetAll().Include(g => g.Budgets).Where(g => g.Id == id).FirstOrDefault();
        //    if (grant == null)
        //    {
        //        return NotFound();
        //    }

        //    var data = grant.Budgets.Select(b => new BudgetViewModel
        //    {
        //        Id = b.Id,
        //        Name = b.Name,
        //        Description = b.Description,
        //        Year = b.FinancialYear,
        //        Amount = b.Amount,
        //        Supplier = _uow.Organizations.FindById(b.SupplierId).Name
        //    });

        //    return Ok(data);
        //}

        //[Route("api/grants/{grantId}/budgets/{budgetId}")]
        //public IHttpActionResult GetBudgets(Guid grantId, Guid budgetId)
        //{
        //    var grant = _uow.Grants.GetAll().Include(g => g.Budgets).Where(g => g.Id == grantId).FirstOrDefault();
        //    if (grant == null)
        //    {
        //        return NotFound();
        //    }

        //    var data = grant.Budgets.Where(b => b.Id == budgetId).Select(b => new BudgetBindingModel
        //    {
        //        Name = b.Name,
        //        Description = b.Description,
        //        FinancialYear = b.FinancialYear,
        //        Amount = b.Amount,
        //        SupplierId = b.SupplierId
        //    }).FirstOrDefault();

        //    return Ok(data);
        //}

        //[Route("api/grants/{grantId}/budgets/{budgetId}")]
        //public IHttpActionResult PutGetBudgets(Guid grantId, Guid budgetId, BudgetBindingModel model)
        //{
        //    var grant = _uow.Grants.GetAll().Include(g => g.Budgets).Where(g => g.Id == grantId).FirstOrDefault();

        //    if (grant == null)
        //    {
        //        return NotFound();
        //    }

        //    var data = grant.Budgets.Where(b => b.Id == budgetId).FirstOrDefault();
        //    var org = _uow.Organizations.FindById(model.SupplierId);

        //    data.Name = model.Name;
        //    data.Description = model.Description;
        //    data.FinancialYear = model.FinancialYear;
        //    data.Amount = model.Amount;
        //    data.Supplier = org;

        //    grant.LastUpdated = DateTime.Now;

        //    _uow.Commit();

        //    return Ok();
        //}


        //[Route("api/grants/{id}/budgets")]
        //public IHttpActionResult Post(Guid id, BudgetBindingModel model)
        //{
        //    //validation
        //    if (!ModelState.IsValid)
        //    {
        //        return BadRequest(ModelState);
        //    }

        //    Grant grant = _uow.Grants.FindById(id);
        //    //var org = _uow.Organizations.FindById(model.Supplier);
        //    if (grant == null)
        //    {
        //        return NotFound();
        //    }
        //    var supplier = _uow.Organizations.FindById(model.SupplierId);
        //    grant.Budgets.Add(new Budget
        //    {
        //        Id = Guid.NewGuid(),
        //        Name = model.Name,
        //        Description = model.Description,
        //        FinancialYear = model.FinancialYear,
        //        Amount = model.Amount,
        //        Supplier = supplier
        //    });
        //    grant.LastUpdated = DateTime.Now;
        //    _uow.Commit();

        //    return Ok();
        //}

        public IHttpActionResult Post(GrantBindingModel model)
        {
            //validation
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var grant = new Grant
            {
                Id = Guid.NewGuid(),
                Code = model.Code,
                Name = model.Name,
                Description = model.Description,
                Objective = model.Objective,
                MaxDuration = model.MaxDuration,
                MaxAward = model.MaxAward,
                Total = model.Total,
                //Agency = _uow.Organizations.FindById(model.Issuer),
                Created = DateTime.Now
            };
            //item.Init(grant.Code, grant.Name, grant.Description, grant.Total, grant.MaxAward);

            _uow.Grants.Add(grant);
            _uow.Save();

            return Ok(grant);
        }