Exemplo n.º 1
0
 public IActionResult Update([Bind("Id,Name,Sponsor,Type,Status,StartDate,EndDate,Description,Cost,Interested")]
                             PlanUpload plan)
 {
     if (ModelState.IsValid)
     {
         _planRepository.Update(plan);
         return(Ok());
     }
     return(BadRequest());
 }
Exemplo n.º 2
0
 public IActionResult Insert(
     [Bind("Name,Sponsor,Type,Status,StartDate,EndDate,Description,Cost,Interested")]
     PlanUpload plan)
 {
     if (ModelState.IsValid)
     {
         var result   = _planRepository.Insert(plan);
         var lastType = result ? _planRepository.GetLastInserted() : null;
         var uri      = Url.Action("Get", new { id = lastType.Id });
         return(Created(uri, lastType));
     }
     return(BadRequest());
 }
Exemplo n.º 3
0
        public bool Update(PlanUpload item)
        {
            using (IDbConnection db = new SqlConnection(ConnectionString))
            {
                if (db.State == ConnectionState.Closed)
                {
                    db.Open();
                }
                DateTime?start = validConvertDate(item.StartDate);
                DateTime?end   = validConvertDate(item.EndDate);

                string SQL = @"UPDATE plans SET
                                  name = @Name,
                                  id_user = @IdSponsor,
                                  id_type = @IdTypePlan,
                                  id_status = @IdStatus,
                                  description = @Description,
                                  cost = @Cost,
                                  start_date = @StartDate,
                                  end_date = @EndDate
                            WHERE id = @Id";

                int result = db.Execute(SQL, new
                {
                    Name        = item.Name,
                    IdSponsor   = item.Sponsor,
                    IdStatus    = item.Status,
                    IdTypePlan  = item.Type,
                    Description = item.Description,
                    Cost        = item.Cost,
                    StartDate   = start,
                    EndDate     = end,
                    Id          = item.Id
                });
                if (!String.IsNullOrEmpty(item.Interested))
                {
                    result += AlterInterested(item.Interested, item.Id);
                }
                return(result > 0);
            }
        }
Exemplo n.º 4
0
        public bool Insert(PlanUpload item)
        {
            using (IDbConnection db = new SqlConnection(ConnectionString))
            {
                if (db.State == ConnectionState.Closed)
                {
                    db.Open();
                }
                var results = db.Execute("sp_insert_plans", new
                {
                    Name           = item.Name,
                    IdSponsor      = item.Sponsor,
                    IdType         = item.Type,
                    IdStatus       = item.Status,
                    InterestedUser = item.Interested,
                    Description    = item.Description,
                    Costs          = item.Cost,
                    StartDate      = validConvertDate(item.StartDate),
                    EndDate        = validConvertDate(item.EndDate)
                }, commandType: CommandType.StoredProcedure);

                return(results > 0);
            }
        }