Exemple #1
0
        public ActionResult Post(bool IsNew, CalendarioModel varCalendario)
        {
            try
            {
                //if (ModelState.IsValid)
                //{
                if (!_tokenManager.GenerateToken())
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                _ICalendarioApiConsumer.SetAuthHeader(_tokenManager.Token);



                var result         = "";
                var CalendarioInfo = new Calendario
                {
                    Clave = varCalendario.Clave
                    , Usuario_que_Registra = varCalendario.Usuario_que_Registra
                };

                result = !IsNew?
                         _ICalendarioApiConsumer.Update(CalendarioInfo, null, null).Resource.ToString() :
                             _ICalendarioApiConsumer.Insert(CalendarioInfo, null, null).Resource.ToString();

                Session["KeyValueInserted"] = result;
                return(Json(result, JsonRequestBehavior.AllowGet));
                //}
                //return Json(false, JsonRequestBehavior.AllowGet);
            }
            catch (ServiceException ex)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #2
0
        public SingleResponse <bool> EliminarCalendario(CalendarioModel calendarioModel)
        {
            SingleResponse <bool> response = new SingleResponse <bool>();

            try
            {
                bool ban = iCalendarioTicketsDataAcces.EliminarCalendario(calendarioModel);
                response.Done(ban, string.Empty);
            }
            catch (DalException e)
            {
                response.Error(e);
            }
            catch (DomainValidationsException e)
            {
                response.SetValidations(e.Validations);
            }
            catch (DomainException e)
            {
                response.Error(e);
            }
            catch (Exception e)
            {
                response.Error(new DomainException(CodesCalendario.ERR_07_04, e));
            }
            return(response);
        }
Exemple #3
0
        public bool EliminarCalendario(CalendarioModel calendarioModel)
        {
            bool ban = true;

            try
            {
                if (!EsDiaInhabil(calendarioModel))
                {
                    iGenericDataAccess.OpenConnection();
                    iGenericDataAccess.Eliminar(new CatDiasHabiles()
                    {
                        IdDiaHabil = calendarioModel.IdDiaHabil
                    });
                    iGenericDataAccess.CloseConnection();
                }
                else
                {
                    throw new DomainException(CodesCalendario.INF_07_01);
                }
            }
            catch (DomainException e)
            {
                ban = false;
                iGenericDataAccess.CloseConnection();
                throw new DomainException(CodesCalendario.INF_07_01, e);
            }
            catch (Exception e)
            {
                ban = false;
                iGenericDataAccess.CloseConnection();
                throw new DalException(CodesCalendario.ERR_07_04, e);
            }
            return(ban);
        }
Exemple #4
0
        public SingleResponse <CalendarioModel> GuardarCalendario(CalendarioModel calendarioModel)
        {
            SingleResponse <CalendarioModel> response = new SingleResponse <CalendarioModel>();

            try
            {
                CalendarioModel calModel = iCalendarioTicketsDataAcces.GuardarCalendario(calendarioModel);
                response.Done(calModel, string.Empty);
            }
            catch (DalException e)
            {
                response.Error(e);
            }
            catch (DomainValidationsException e)
            {
                response.SetValidations(e.Validations);
            }
            catch (DomainException e)
            {
                response.Error(e);
            }
            catch (Exception e)
            {
                response.Error(new DomainException(CodesCalendario.ERR_07_03, e));
            }
            return(response);
        }
Exemple #5
0
 public CalendarioModel GuardarCalendario(CalendarioModel calendarioModel)
 {
     try
     {
         iGenericDataAccess.OpenConnection();
         IList <CatDiasHabiles> findDia = iGenericDataAccess.
                                          Consultar(new CatDiasHabiles()
         {
             Dia = calendarioModel.Dia.Date
         },
                                                    new OptionsQueryZero()
         {
             ExcludeNumericsDefaults = true,
             ExcludeBool             = true
         });
         if (findDia.Count > 0)
         {
             throw new DalException(CodesCalendario.INF_07_00);
         }
         else
         {
             CatDiasHabiles obj = iGenericDataAccess.
                                  Guardar(new CatDiasHabiles()
             {
                 PersonaId     = 177080,
                 Dia           = calendarioModel.Dia,
                 FechaRegistro = DateTime.Today
             });
             iGenericDataAccess.OpenConnection();
             calendarioModel.IdDiaHabil = obj.IdDiaHabil;
             calendarioModel.PersonaId  = obj.PersonaId;
             calendarioModel.FechaDia   = DateToString(obj.Dia);
         }
     }
     catch (DalException e)
     {
         throw e;
     }
     catch (Exception e)
     {
         iGenericDataAccess.CloseConnection();
         throw new DalException(CodesCalendario.ERR_07_03, e);
     }
     return(calendarioModel);
 }
Exemple #6
0
        public HttpResponseMessage Put(int Id, string cultura, CalendarioModel calendario)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (cultura != Localizacion.CulturaPorDefecto)
                    {
                        Calendario      _calendario           = calendarioRepository.GetById(new string[] {}, (p => p.Id == Id));
                        CalendarioModel _calendarioPorDefecto = new CalendarioModel();
                        // Solo funciona el Mapper si se ha configurado el Mapper con Mapper.CreateMap<EmpresaModel, EmpresaModel>(); Se está creando en la carpeta mappers.
                        _calendarioPorDefecto = AutoMapper.Mapper.Map <CalendarioModel, CalendarioModel>(calendario, _calendarioPorDefecto);

                        _calendarioPorDefecto.Nombre   = _calendario.Nombre;
                        _calendarioPorDefecto.Variante = _calendario.Variante;

                        var command = AutoMapper.Mapper.Map <CalendarioModel, CreateOrUpdateCalendarioCommand>(_calendarioPorDefecto);
                        var result  = commandBus.Submit(command);
                    }
                    else
                    {
                        var command = AutoMapper.Mapper.Map <CalendarioModel, CreateOrUpdateCalendarioCommand>(calendario);
                        var result  = commandBus.Submit(command);
                    }
                    Calendario_Idioma _calendarioIdioma = calendario_IdiomaRepository.GetMany(t => t.IdRegistro == calendario.Id && t.Cultura == cultura).FirstOrDefault();
                    var commandIdioma = AutoMapper.Mapper.Map <Calendario_IdiomaModel, CreateOrUpdateCalendario_IdiomaCommand>(new Calendario_IdiomaModel {
                        Id = (_calendarioIdioma != null ? _calendarioIdioma.Id : (int)0), IdRegistro = calendario.Id, Cultura = cultura, Nombre = calendario.Nombre, Variante = calendario.Variante
                    });
                    var resultIdioma = commandBus.Submit(commandIdioma);
                    return(Request.CreateResponse <CalendarioModel>(HttpStatusCode.OK, calendario));
                }
                else
                {
                    var errors = new Dictionary <string, IEnumerable <string> >();
                    foreach (var keyValue in ModelState)
                    {
                        errors[keyValue.Key] = keyValue.Value.Errors.Select(e => (!string.IsNullOrWhiteSpace(e.ErrorMessage) ? e.ErrorMessage : (e.Exception != null ? e.Exception.Message : string.Empty)));
                    }
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            } catch (Exception _excepcion) {
                log.Error(_excepcion);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
            }
        }
Exemple #7
0
 public HttpResponseMessage Post(string cultura, CalendarioModel calendario)
 {
     try {
         if (ModelState.IsValid)
         {
             if (calendario.Id == 0)
             {
                 var command = AutoMapper.Mapper.Map <CalendarioModel, CreateOrUpdateCalendarioCommand>(calendario);
                 var result  = commandBus.Submit(command);
                 if (result.Success)
                 {
                     var commandIdioma = AutoMapper.Mapper.Map <Calendario_IdiomaModel, CreateOrUpdateCalendario_IdiomaCommand>(new Calendario_IdiomaModel {
                         IdRegistro = command.Id, Cultura = cultura, Nombre = command.Nombre, Variante = command.Variante
                     });
                     var resultIdioma = commandBus.Submit(commandIdioma);
                     if (resultIdioma.Success)
                     {
                         calendario = AutoMapper.Mapper.Map <CreateOrUpdateCalendarioCommand, CalendarioModel>(command);
                         var    response = Request.CreateResponse <CalendarioModel>(HttpStatusCode.Created, calendario);
                         string uri      = Url.Route(null, new { Id = calendario.Id });
                         response.Headers.Location = new Uri(Request.RequestUri, uri);
                         return(response);
                     }
                 }
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.BadRequest, "No se puede insertar el registro porque ya existe otro con la misma clave. Por favor, revísela."));
             }
         }
         else
         {
             var errors = new Dictionary <string, IEnumerable <string> >();
             foreach (var keyValue in ModelState)
             {
                 errors[keyValue.Key] = keyValue.Value.Errors.Select(e => (!string.IsNullOrWhiteSpace(e.ErrorMessage) ? e.ErrorMessage : (e.Exception != null ? e.Exception.Message : string.Empty)));
             }
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
         }
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     } catch (Exception _excepcion) {
         log.Error(_excepcion);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, _excepcion));
     }
 }
Exemple #8
0
        public ActionResult AddCalendario(int rowIndex = 0, int functionMode = 0, string id = "0")
        {
            int ModuleId = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0;

            ViewBag.currentRowIndex = rowIndex;
            ViewBag.functionMode    = functionMode;
            ViewBag.Consult         = false;
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 45132);

            ViewBag.Permission = permission;
            if (!_tokenManager.GenerateToken())
            {
                return(null);
            }
            _ICalendarioApiConsumer.SetAuthHeader(_tokenManager.Token);
            CalendarioModel varCalendario = new CalendarioModel();


            if (id.ToString() != "0")
            {
                var CalendariosData = _ICalendarioApiConsumer.ListaSelAll(0, 1000, "Calendario.Clave=" + id, "").Resource.Calendarios;

                if (CalendariosData != null && CalendariosData.Count > 0)
                {
                    var CalendarioData = CalendariosData.First();
                    varCalendario = new CalendarioModel
                    {
                        Clave = CalendarioData.Clave
                        , Usuario_que_Registra = CalendarioData.Usuario_que_Registra
                    };
                }
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }



            return(PartialView("AddCalendario", varCalendario));
        }
Exemple #9
0
        public bool EsDiaInhabil(CalendarioModel calendario)
        {
            try
            {
                iGenericDataAccess.OpenConnection();
                IList <CatDiasInhabiles> listCatDiasInhabiles = iGenericDataAccess.Consultar(
                    new CatDiasInhabiles(),
                    new OptionsQueryZero()
                {
                    ExcludeNumericsDefaults = true,
                    ExcludeBool             = true,
                    WhereComplementary      = "IdDiaHabil = " + calendario.IdDiaHabil
                });

                iGenericDataAccess.CloseConnection();

                return(listCatDiasInhabiles[0].Dia.Date <= DateTime.Today);
            }
            catch (Exception e)
            {
                iGenericDataAccess.CloseConnection();
                throw new DalException(CodesSeguiminetorTickets.ERR_00_11, e);
            }
        }
Exemple #10
0
        public ActionResult Create(int Id = 0, int consult = 0, int ModuleId = 0)
        {
            if (ModuleId == 0)
            {
                ModuleId = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0;
            }
            else
            {
                Session["CurrentModuleId"] = ModuleId;
            }
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 45132, ModuleId);

            if ((!permission.New && Id.ToString() == "0") || (!permission.Edit && Id.ToString() != "0" && (!permission.Consult && consult == 1)))
            {
                Response.Redirect("~/");
            }
            ViewBag.Permission = permission;
            var varCalendario = new CalendarioModel();

            varCalendario.Clave = Id;

            ViewBag.ObjectId  = "45132";
            ViewBag.Operation = "New";

            ViewBag.IsNew = true;



            if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0"))
            {
                ViewBag.IsNew     = false;
                ViewBag.Operation = "Update";

                _tokenManager.GenerateToken();
                _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                _ICalendarioApiConsumer.SetAuthHeader(_tokenManager.Token);
                var CalendariosData = _ICalendarioApiConsumer.ListaSelAll(0, 1000, "Calendario.Clave=" + Id, "").Resource.Calendarios;

                if (CalendariosData != null && CalendariosData.Count > 0)
                {
                    var CalendarioData = CalendariosData.First();
                    varCalendario = new CalendarioModel
                    {
                        Clave = CalendarioData.Clave
                        , Usuario_que_Registra = CalendarioData.Usuario_que_Registra
                    };
                }
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }



            ViewBag.Consult = consult == 1;
            if (consult == 1)
            {
                ViewBag.Operation = "Consult";
            }

            var viewInEframe  = false;
            var isPartial     = false;
            var isMR          = false;
            var nameMR        = string.Empty;
            var nameAttribute = string.Empty;

            if (Request.QueryString["isPartial"] != null)
            {
                isPartial = Convert.ToBoolean(Request.QueryString["isPartial"]);
            }

            if (Request.QueryString["isMR"] != null)
            {
                isMR = Convert.ToBoolean(Request.QueryString["isMR"]);
            }

            if (Request.QueryString["nameMR"] != null)
            {
                nameMR = Request.QueryString["nameMR"].ToString();
            }

            if (Request.QueryString["nameAttribute"] != null)
            {
                nameAttribute = Request.QueryString["nameAttribute"].ToString();
            }

            if (Request.QueryString["viewInEframe"] != null)
            {
                viewInEframe = Convert.ToBoolean(Request.QueryString["viewInEframe"]);
            }

            ViewBag.isPartial     = isPartial;
            ViewBag.isMR          = isMR;
            ViewBag.nameMR        = nameMR;
            ViewBag.nameAttribute = nameAttribute;
            ViewBag.viewInEframe  = viewInEframe;


            return(View(varCalendario));
        }
 public SingleResponse <bool> EliminarCalendario(CalendarioModel calendarioModel)
 {
     return(iCalendarioTicketsBusiness.EliminarCalendario(calendarioModel));
 }
 public SingleResponse <CalendarioModel> GuardarCalendario(CalendarioModel calendarioModel)
 {
     return(iCalendarioTicketsBusiness.GuardarCalendario(calendarioModel));
 }