Пример #1
0
 public ActionResult Edit(int id)
 {
     if (!isAuthenticated() || !loggedUser.isAdmin)
         return new HttpUnauthorizedResult();
     else
     {
         ActivityViewModel model = new ActivityViewModel();
         Activity activity = new Activity().get(id, loggedUser.Unit);
         model.Id = activity.Id;
         model.Name = activity.Name;
         model.Date = activity.Date;
         model.Place = activity.Place;
         model.Obs = activity.Obs;
         return View(model);
     }
 }
Пример #2
0
        public ActionResult Edit(ActivityViewModel model, string hour, string minute)
        {
            if (!isAuthenticated() || !loggedUser.isAdmin)
                return new HttpUnauthorizedResult();
            else
            {
                if (ModelState.IsValid)
                {
                    Activity activity = new Activity();
                    Result result = activity.update(model.Id, model.Name,
                        new DateTime(model.Date.Year, model.Date.Month, model.Date.Day, new Common().convertNumber(hour), new Common().convertNumber(minute), 0),
                        model.Place,
                        model.Obs,
                        loggedUser.Unit);
                    if (result.Success)
                        return RedirectToAction("Index");
                    else
                        ModelState.AddModelError("", "Ocorreu um erro ao atualizar atividade");
                }

                return View(model);
            }
        }
Пример #3
0
 public List<Activity> getAll(int unitId)
 {
     List<Activity> list = new List<Activity>();
     foreach (List<string> data in database.retrieveData("select id, name, " + common.formatDate("scheduled_by") + ", place, obs from lds_activity where unit_id = @unit_id order by scheduled_by asc", unitId))
     {
         Activity activity = new Activity();
         activity.Id = common.convertNumber(data[0]);
         activity.Name = data[1];
         activity.Date = common.convertDate(data[2]);
         activity.Place = data[3];
         activity.Obs = data[4];
         list.Add(activity);
     }
     return list;
 }
Пример #4
0
 public Activity get(int id, int unitId)
 {
     Activity activity = null;
     foreach (List<string> data in database.retrieveData("select id, name, " + common.formatDate("scheduled_by") + ", place, obs from lds_activity where id = @id and unit_id = @unit_id", id, unitId))
     {
         activity = new Activity();
         activity.Id = common.convertNumber(data[0]);
         activity.Name = data[1];
         activity.Date = common.convertDate(data[2]);
         activity.Place = data[3];
         activity.Obs = data[4];
     }
     return activity;
 }
Пример #5
0
 public List<Activity> getNextNMonths(int nInterval, int unitId)
 {
     List<Activity> list = new List<Activity>();
     foreach (List<string> data in database.retrieveData("select id, name, " + common.formatDate("scheduled_by") +
         ", place, obs from lds_activity where scheduled_by >= date_sub(curdate(), interval 1 day) and scheduled_by < DATE_ADD(curdate(), INTERVAL " + nInterval + " MONTH) and unit_id = @unit_id order by scheduled_by asc", unitId))
     {
         Activity activity = new Activity();
         activity.Id = common.convertNumber(data[0]);
         activity.Name = data[1];
         activity.Date = common.convertDate(data[2]);
         activity.Place = data[3];
         activity.Obs = data[4];
         list.Add(activity);
     }
     return list;
 }