Exemple #1
0
        public JsonResult Crear([Bind(Include = "draft_law_id,draft_law_number,title,author,origin,date_presentation,date_presentation_text,commission_id,debate_speaker,debate_speaker2,debate_speaker3,debate_speaker4,status,status_comment,interest_area_id,initiative,summary,link")] DraftLawViewModel pDraftLawViewModel)
        {
            // TODO: Add insert logic here


            if (pDraftLawViewModel == null)
            {
                // return HttpNotFound();

                return(Json(new
                {
                    message_error = "Datos inavalidos",
                    status = "0",
                }));
            }
            pDraftLawViewModel.date_presentation = DateTime.ParseExact(pDraftLawViewModel.date_presentation_text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            pDraftLawViewModel.draft_law_id      = 0;

            pDraftLawViewModel.user_id_created = AuthorizeUserAttribute.UsuarioLogeado().user_id;

            pDraftLawViewModel.commission    = "";
            pDraftLawViewModel.interest_area = "";
            List <ImportError>       oErrores = null;
            DraftLawBL               oBL      = new DraftLawBL();
            List <DraftLawViewModel> lista    = new List <DraftLawViewModel>();

            lista.Add(pDraftLawViewModel);
            PeriodBL        oPeriodBL = new PeriodBL();
            PeriodViewModel oPeriod   = oPeriodBL.ObtenerVigente();

            oErrores = ValidarPeriodo(oPeriod, oErrores);
            if (oErrores.Count > 0)
            {
                return(Json(new { successfully = 0, errores = oErrores }));
            }

            if (VerificarPonentes(lista, out oErrores))
            {
                DraftLawBL               oDraftLawBL       = new DraftLawBL();
                CommissionBL             oCommissionBL     = new CommissionBL();
                InterestAreaBL           oInterestAreaBL   = new InterestAreaBL();
                DraftLawStatusBL         oDraftLawStatusBL = new DraftLawStatusBL();
                OriginBL                 oOriginBL         = new OriginBL();
                Dictionary <string, int> commisions        = new Dictionary <string, int>();
                Dictionary <string, int> origins           = oOriginBL.ObtenerDiccionarioPorNombre(lista.Select(a => a.origin).Distinct().ToList(), AuthorizeUserAttribute.UsuarioLogeado().user_id);
                Dictionary <string, int> interest_areas    = new Dictionary <string, int>();
                Dictionary <string, DraftLawStatusViewModel> draftlaw_status = oDraftLawStatusBL.ObtenerDiccionarioPorNombre(lista.Select(a => a.status).Distinct().ToList(), AuthorizeUserAttribute.UsuarioLogeado().user_id);

                oDraftLawBL.Import(oPeriod, lista, origins, commisions, interest_areas, draftlaw_status, AuthorizeUserAttribute.UsuarioLogeado().user_id);
                // NotificacionNuevoProyectoLey(lista);
            }


            // oBL.Agregar(pDraftLawViewModel);
            if (oErrores.Count == 0)
            {
                return(Json(new { successfully = 1 }));
            }
            else
            {
                return(Json(new { successfully = 0, errores = oErrores }));
            }

            // return RedirectToAction("Index");
        }
Exemple #2
0
        public ActionResult UploadFiles()
        {
            List <ImportError> oErrores = null;

            // Checking no of files injected in Request object
            if (Request.Files.Count > 0)
            {
                try
                {
                    //  Get all files from Request object
                    HttpFileCollectionBase files = Request.Files;
                    for (int i = 0; i < files.Count; i++)
                    {
                        //string path = AppDomain.CurrentDomain.BaseDirectory + "Uploads/";
                        //string filename = Path.GetFileName(Request.Files[i].FileName);

                        HttpPostedFileBase file  = files[i];
                        string             fname = Guid.NewGuid().ToString() + ".xlsx";

                        fname = Path.Combine(Server.MapPath("~/Uploads/"), fname);
                        file.SaveAs(fname);
                        DataTable       dt        = Util.ReadExcelToDataTable(fname);
                        PeriodBL        oPeriodBL = new PeriodBL();
                        PeriodViewModel oPeriod   = oPeriodBL.ObtenerVigente();

                        oErrores = ValidarPeriodo(oPeriod, oErrores);
                        List <DraftLawViewModel> lista = new List <DraftLawViewModel>();
                        if (oErrores.Count == 0)
                        {
                            lista = ConvertirDatatable(dt, out oErrores);
                        }
                        if (oErrores.Count == 0)
                        {
                            if (VerificarPonentes(lista, out oErrores))
                            {
                                DraftLawBL               oDraftLawBL       = new DraftLawBL();
                                CommissionBL             oCommissionBL     = new CommissionBL();
                                InterestAreaBL           oInterestAreaBL   = new InterestAreaBL();
                                DraftLawStatusBL         oDraftLawStatusBL = new DraftLawStatusBL();
                                OriginBL                 oOriginBL         = new OriginBL();
                                Dictionary <string, int> commisions        = oCommissionBL.ObtenerDiccionarioPorNombre(lista.Select(a => a.commission).Distinct().ToList(), AuthorizeUserAttribute.UsuarioLogeado().user_id);
                                Dictionary <string, int> origins           = oOriginBL.ObtenerDiccionarioPorNombre(lista.Select(a => a.origin).Distinct().ToList(), AuthorizeUserAttribute.UsuarioLogeado().user_id);
                                Dictionary <string, int> interest_areas    = oInterestAreaBL.ObtenerDiccionarioPorNombre(lista.Select(a => a.interest_area).Distinct().ToList(), AuthorizeUserAttribute.UsuarioLogeado().user_id);
                                Dictionary <string, DraftLawStatusViewModel> draftlaw_status = oDraftLawStatusBL.ObtenerDiccionarioPorNombre(lista.Select(a => a.status).Distinct().ToList(), AuthorizeUserAttribute.UsuarioLogeado().user_id);

                                oDraftLawBL.Import(oPeriod, lista, origins, commisions, interest_areas, draftlaw_status, AuthorizeUserAttribute.UsuarioLogeado().user_id);
                                // NotificacionNuevoProyectoLey(lista);
                            }
                        }
                    }
                    if (oErrores.Count == 0)
                    {
                        return(Json(new { successfully = 1 }));
                    }
                    else
                    {
                        return(Json(new { successfully = 0, errores = oErrores }));
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                    if (ex.Data.Contains("RepositoryMessage"))
                    {
                        logger.Error(ex.Data["RepositoryMessage"].ToString());
                    }
                    return(Json(new { successfully = -1, message = "Ha ocurrido un error. Detalle error: " + ex.Message }));
                }
            }
            else
            {
                return(Json("No files selected."));
            }
        }