Ejemplo n.º 1
0
 public bool add(PeriodoDTO Periodo)
 {
     using (var context = getContext())
     {
         try
         {
             Periodo nuevo = new Periodo();
             nuevo.Nombre = Periodo.Nombre;
             nuevo.FechaInicio = Periodo.FechaInicio;
             nuevo.FechaFin = Periodo.FechaFin;
             nuevo.Active = true;
             nuevo.IdEmpresa = Periodo.IdEmpresa;
             context.Periodo.Add(nuevo);
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Ejemplo n.º 2
0
 public ActionResult AddPeriodo(PeriodoDTO dto)
 {
     if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
     try
     {
         PeriodoBL objBL = new PeriodoBL();
         if (dto.IdPeriodo == 0)
         {
             if (objBL.add(dto))
             {
                 createResponseMessage(CONSTANTES.SUCCESS);
                 return RedirectToAction("Periodos");
             }
         }
         else if (dto.IdPeriodo != 0)
         {
             if (objBL.update(dto))
             {
                 createResponseMessage(CONSTANTES.SUCCESS);
                 return RedirectToAction("Periodos");
             }
             else
             {
                 createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
             }
         }
         else
         {
             createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
         }
     }
     catch (Exception e)
     {
         if (dto.IdPeriodo != 0)
             createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_UPDATE_MESSAGE);
         else createResponseMessage(CONSTANTES.ERROR, CONSTANTES.ERROR_INSERT_MESSAGE);
     }
     TempData["Periodo"] = dto;
     return RedirectToAction("Periodo");
 }
Ejemplo n.º 3
0
        public ActionResult Periodo(int? id = null)
        {
            if (!this.currentUser()) { return RedirectToAction("Ingresar"); }
            if (!this.isAdministrator()) { return RedirectToAction("Index"); }
            ViewBag.Title = "Periodo";
            MenuNavBarSelected(8, 1);

            UsuarioDTO currentUser = getCurrentUser();

            PeriodoBL objBL = new PeriodoBL();

            var objSent = TempData["Periodo"];
            if (objSent != null) { TempData["Periodo"] = null; return View(objSent); }

            PeriodoDTO obj;
            if (id != null)
            {
                obj = objBL.getPeriodoEnEmpresa((int)currentUser.IdEmpresa, (int)id);
                if (obj == null) return RedirectToAction("Periodos");
                if (obj.IdEmpresa != currentUser.IdEmpresa) return RedirectToAction("Periodos");
                return View(obj);
            }
            obj = new PeriodoDTO();
            obj.IdEmpresa = currentUser.IdEmpresa;

            int dyear = DateTime.Now.Year;
            obj.FechaInicio = new DateTime(dyear, 1, 1);
            obj.FechaFin = new DateTime(dyear, 12, 31);
            return View(obj);
        }
Ejemplo n.º 4
0
 public bool update(PeriodoDTO Periodo)
 {
     using (var context = getContext())
     {
         try
         {
             var row = context.Periodo.Where(x => x.IdPeriodo == Periodo.IdPeriodo).SingleOrDefault();
             row.Nombre = Periodo.Nombre;
             row.FechaInicio = Periodo.FechaInicio;
             row.FechaFin = Periodo.FechaFin;
             row.Active = Periodo.Active;
             row.IdEmpresa = Periodo.IdEmpresa;
             context.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }