Пример #1
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();

                using (Lib.Repositories.ResponseFormRepository rep = new Lib.Repositories.ResponseFormRepository(this.ActiveUser))
                {
                    var responseForms = rep.getRanking();

                    var track = new List<string>();

                    var result = responseForms.Select(rf => new
                    {
                        Id = rf.Id,
                        TotalScore = String.Format("{0}", Math.Round(rf.TotalScore,2)),
                        CityState = String.Format("{0}/{1}", rf.City.Name, rf.City.StateId),
                        State = rf.City.StateId,
                        BaseBlocks = rf.BaseForm.BaseBlocks.Select(bb => new
                        {
                            Id = bb.Id,
                            IdCrypt = Commons.SecurityUtils.criptografar(bb.Id.ToString()),
                            Name = bb.Name,
                            Score = bb.calculateNB(rf.Id, ref track),
                            BaseSubblocks = bb.BaseSubBlocks.Select(bsb => new
                            {
                                Id = bsb.Id,
                                Letter = bsb.Name[0].ToString().ToUpper(),
                                Name = bsb.Name,
                                Graphic = String.Format("{0}/{1}. <br/> {2} N/A.", "2", "5", "15"),
                                Percent = bsb.calculatePercent(rf.Id),
                                Color = bsb.getColorByPercent(rf.Id)
                            })
                        })
                    }).ToList();

                    context.Response.Write(serializer.Serialize(result));
                    context.Response.StatusCode = 200;
                    context.Response.ContentType = "application/json";
                }
            }
            catch (Exception ex)
            {
                Lib.Log.ErrorLog.saveError("Site.Handlers.Ranking.ProcessRequest", ex);
                context.Response.StatusCode = 500;
                context.Response.Write(ex.Message);
            }
        }
Пример #2
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                List<Lib.Entities.ResponseForm> responseForms = null;

                var periodIdString = context.Request.Form["periodId"];
                var checks = context.Request.Form["chbs"].Split(",".ToCharArray());

                var accepted = false;
                var submitted = false;
                var completed = false;
                var incompleted = false;

                //accepted,submitted,completed,incompleted
                if (checks.Contains("accepted")) accepted = true;
                if (checks.Contains("submitted")) submitted = true;
                if (checks.Contains("completed")) completed = true;
                if (checks.Contains("incompleted")) incompleted = true;

                long periodId = 0;
                long.TryParse(periodIdString, out periodId);

                using (Lib.Repositories.ResponseFormRepository repository = new Lib.Repositories.ResponseFormRepository(this.ActiveUser))
                {
                    responseForms = repository.getResponseFormsByUserId(this.ActiveUser.Id);

                    if (periodId > 0)
                    {
                        responseForms = responseForms.Where(f => f.BaseForm.PeriodId == periodId).ToList();
                    }

                    if (responseForms != null)
                    {
                        var result = responseForms.Select(rf => new
                        {
                            Id = rf.Id,
                            IdCrypt = Commons.SecurityUtils.criptografar(rf.Id.ToString()),
                            CityState = rf.City != null ? String.Format("{0} - {1}", rf.City.Name, rf.City.StateId) : "N/I",
                            State = rf.City != null ? rf.City.StateId : "N/I",
                            ResponsableUser = rf.User != null ? rf.User.Name : "",
                            BaseFormName = rf.BaseForm.Name,
                            PeriodName = rf.BaseForm.Period.Name,
                            TotalAnswers = rf.Answers.Count,
                            TotalQuestions = rf.getTotalQuestions(),
                            StatusSubmit = rf.Submits != null && rf.Submits.Count > 0 ? Lib.Enumerations.EnumManager.getStringFromSubmitType(rf.Submits.OrderBy(f => f.Id).LastOrDefault().StatusEnum) : "Em andamento"
                        }).ToList();

                        if (!completed)
                        {
                            result = result.Where(f => f.TotalAnswers != f.TotalQuestions).ToList();
                        }

                        if (!incompleted)
                        {
                            result = result.Where(f => f.TotalAnswers == f.TotalQuestions).ToList();
                        }

                        if (this.ActiveUser.UserTypeEnum == Lib.Enumerations.UserType.Entity)
                        {
                            if (this.ActiveUser.Groups != null && this.ActiveUser.Groups.Count > 0)
                            {
                                if (!accepted)
                                {
                                    result = result.Where(s => s.StatusSubmit != "Approved").ToList();
                                }

                                if (!submitted)
                                {
                                    result = result.Where(s => s.StatusSubmit != "Submitted").ToList();
                                }
                            }
                        }

                        context.Response.Write(serializer.Serialize(result));
                        context.Response.StatusCode = 200;
                        context.Response.ContentType = "application/json";
                    }
                }
            }
            catch (Exception ex)
            {
                Lib.Log.ErrorLog.saveError("Site.Handlers.ResponseForm.ProcessRequest", ex);
                context.Response.StatusCode = 500;
                context.Response.Write(ex.Message);
            }
        }
Пример #3
0
        private Lib.Entities.ResponseForm loadRepeater()
        {
            using (Lib.Repositories.ResponseFormRepository repo = new Lib.Repositories.ResponseFormRepository(this.ActiveUser))
            {
                Lib.Entities.ResponseForm form = repo.getInstanceById(long.Parse(hdnResponseId.Value));

                litTracking.Text = form.TrackingNote.Replace("\r\n", "<br/>");

                this.form = form;

                //Altera o indice para mostrar incremental, conforme solicitado em FDT-69
                int count = 1;
                if (this.form.BaseForm.BaseBlocks != null)
                {
                    this.form.BaseForm.BaseBlocks.ForEach(bb =>
                        {
                            if (bb.BaseSubBlocks != null)
                            {
                                bb.BaseSubBlocks.ForEach(bsb =>
                                {
                                    if (bsb.BaseQuestions != null)
                                    {
                                        bsb.BaseQuestions.ForEach(bq =>
                                        {
                                            bq.Index = count;
                                            count++;
                                        });
                                    }
                                });
                            }
                        });
                }

                //Informa os  colaboradores e o responsável
                using (Lib.Repositories.UserRepository ctx = new Lib.Repositories.UserRepository(this.ActiveUser))
                {
                    if (this.form.CityId.HasValue && this.form.BaseForm != null)
                    {
                        phRespCollab.Visible = true;
                        var responsable = ctx.getResponsable(this.form.CityId.Value, this.form.BaseForm.PeriodId);
                        var collaborators = ctx.getCollaborators(this.form.CityId.Value, this.form.BaseForm.PeriodId);

                        if (responsable != null)
                            lblResponsable.Text = responsable.Name;

                        if (collaborators != null && collaborators.Count > 0)
                            lblCollaborator.Text = String.Join(",", collaborators.Select(c => c.Name).ToList());
                    }
                }

                rptBlocks.DataSource = this.form.BaseForm.BaseBlocks;
                rptBlocks.DataBind();

                return form;
            }
        }
        public override void ProcessRequest(HttpContext context)
        {
            List<Lib.Entities.ResponseForm> responseForms = null;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            long periodId = 0;

            if (!String.IsNullOrEmpty(context.Request.Form["periodId"]))
            {
                var periodIdEncoded = context.Request.Form["periodId"];
                var periodIdString = Commons.SecurityUtils.descriptografar(periodIdEncoded);
                long.TryParse(periodIdString, out periodId);
            }

            using (Lib.Repositories.ResponseFormRepository rep = new Lib.Repositories.ResponseFormRepository(this.ActiveUser))
            {
                if (periodId > 0)
                {
                    responseForms = rep.getResponseFormsByPeriod(periodId);
                }
                else
                {
                    responseForms = rep.getActualOrLastPeriodResponseForms();
                }
            }

            if (responseForms != null)
            {
                //Adicionado tratamento para retornar todos os questionários de entidades e que possuem o status de submissão
                var result = responseForms.Where(f => f.User.UserTypeEnum == Lib.Enumerations.UserType.Entity && f.Submits != null && f.Submits.Count > 0).Select(rf => new
                {
                    Id = rf.Id,
                    UserName = rf.User.Name,
                    UserId = HttpUtility.UrlEncode(Commons.SecurityUtils.criptografar(rf.User.Id.ToString())),
                    UserType = Lib.Enumerations.EnumManager.getStringFromUserType(rf.User.UserTypeEnum, rf.User.Network),
                    ActiveUserType = this.ActiveUser.UserTypeEnum.ToString(),
                    SubmitStatus = Lib.Enumerations.EnumManager.getStringFromSubmitType(rf.Submits.OrderBy(f => f.Id).LastOrDefault().StatusEnum),
                    SubmitStatusEnum = rf.Submits.OrderBy(f => f.Id).LastOrDefault().StatusEnum.ToString(),
                    SubmitId = rf.Submits.OrderBy(f => f.Id).LastOrDefault().Id.ToString(),
                    UserAlreadyReview = rf.Reviews != null && rf.Reviews.Where(re => re.UserId == this.ActiveUser.Id).FirstOrDefault() != null ? true : false,
                    UserIsMaster = this.ActiveUser.UserTypeEnum == Lib.Enumerations.UserType.Master,
                    Reviews = rf.Reviews.Select(r => new
                    {
                        Id = r.Id,
                        Accepted = r.Accepted,
                        UserName = r.User.Name,
                    }),
                    PositiveReviews = rf.Reviews.Where(f => f.Accepted).Select(r => new
                    {
                        Id = r.Id,
                        Accepted = r.Accepted,
                        UserName = r.User.Name
                    }),
                    NegativeReviews = rf.Reviews.Where(f => f.Accepted == false).Select(r => new
                    {
                        Id = r.Id,
                        Accepted = r.Accepted,
                        UserName = r.User.Name
                    })
                }).ToList();

                context.Response.ContentType = "application/json";
                context.Response.Write(serializer.Serialize(result));
            }
            else
            {
                context.Response.Write("");
            }
        }
Пример #5
0
        private long saveResponseForm(DataTableCollection tables)
        {
            Lib.Entities.ResponseForm form = new Lib.Entities.ResponseForm();
            form.Answers = new List<Lib.Entities.Answer>();
            form.UserId = int.Parse(ddlEntidades.SelectedValue);
            form.CityId = int.Parse(hdnCityId.Value);

            Lib.Entities.Answer resposta = null;
            foreach (DataTable table in tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    resposta = new Lib.Entities.Answer();
                    resposta.BaseQuestionId = long.Parse(row.ItemArray[5].ToString());
                    resposta.Observation = row.ItemArray[3].ToString();

                    decimal score = 0;
                    if (decimal.TryParse(row.ItemArray[2].ToString(), NumberStyles.Any, new System.Globalization.CultureInfo("en-US"), out score))
                    {
                        resposta.Score = score;
                    }

                    form.BaseFormId = long.Parse(row.ItemArray[6].ToString());
                    form.Answers.Add(resposta);

                    resposta = null;
                }
            }

            using (Lib.Repositories.ResponseFormRepository rep = new Lib.Repositories.ResponseFormRepository(this.ActiveUser))
            {
                rep.save(form);
            }

            return form.Id;
        }
Пример #6
0
        private void loadRanking()
        {
            using (Lib.Repositories.ResponseFormRepository repo = new Lib.Repositories.ResponseFormRepository(this.ActiveUser))
            {
                var responsesForms = repo.getAll();

                var listObjForm = responsesForms.Select(f => new
                {
                    CityName = f.City.Name + " (" + f.City.StateId + ")",
                    FormName = f.BaseForm.Name,
                    Id = f.Id,
                    TotalScore = f.TotalScore,
                    UserName = f.User.Name
                });

                gvFormsRanking.DataSource = listObjForm.OrderByDescending(f => f.TotalScore).ToList();
                gvFormsRanking.DataBind();
            }
        }