public override void ProcessRequest(HttpContext context)
        {
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var sPeriodId = context.Request.Form["pId"];
                var sCityId = context.Request.Form["cId"];

                long periodId = 0;
                long.TryParse(Commons.SecurityUtils.descriptografar(sPeriodId), out periodId);

                long cityId = 0;

                if (!String.IsNullOrWhiteSpace(sCityId))
                    long.TryParse(Commons.SecurityUtils.descriptografar(sCityId), out cityId);

                using (Lib.Repositories.UserRepository repository = new Lib.Repositories.UserRepository(this.ActiveUser))
                {
                    var requests = cityId > 0 ? repository.getAllRequestsFromCity(cityId, periodId) : repository.getAllRequestsByPeriod(periodId);

                    var ret = requests.Select(f => new
                    {
                        Id = Commons.SecurityUtils.criptografar(f.Id.ToString()),
                        EntityName = f.User.Name,
                        EntityId = HttpUtility.UrlEncode( Commons.SecurityUtils.criptografar(f.UserId.ToString())),
                        RequestDate = f.RequestDate.ToString("dd/MM/yyyy"),
                        RequestType = f.RequestType,
                        RequestStatus = f.Status,
                        CityName = f.City.Name,
                        CityId = HttpUtility.UrlEncode( Commons.SecurityUtils.criptografar(f.CityId.ToString()))
                    }).ToList();

                    context.Response.ContentType = "application/json";
                    context.Response.Write(serializer.Serialize(ret));

                }
            }
            catch (Exception ex)
            {
                Lib.Log.ErrorLog.saveError("Web.Handler.GroupCities.GetRequests.ProcessRequest", ex);
                context.Response.StatusCode = 500;
                context.Response.Write(String.Format(Resources.Message.unknow_error, ex.Message));
            }
        }
Ejemplo n.º 2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            using (Lib.Repositories.UserRepository repostory = new Lib.Repositories.UserRepository(null))
            {
                Lib.Entities.User user = repostory.authenticateEntityAndComum(txtUser.Text, txtPassword.Text);

                if (user != null)
                {
                    page.login(user, true);
                }
                else
                {
                    foreach (string error in repostory.Errors)
                    {
                        lblMessage.Text = error;
                    }
                }
            }
        }
        public override void ProcessRequest(HttpContext context)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var sPeriodId= context.Request.Form["periodId"];

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

            using (Lib.Repositories.UserRepository repository = new Lib.Repositories.UserRepository(this.ActiveUser))
            {
                var cities = repository.citiesRequests(this.ActiveUser.Id, periodId);

                var ret = cities.Select(f => new
                {
                    CityName = f.City.Name,
                    StateName = f.City.State.Name,
                    RequestStatus = Lib.Enumerations.EnumManager.getStringFromRequestStatus(f.RequestStatusEnum)
                }).ToList();

                context.Response.ContentType = "application/json";
                context.Response.Write(serializer.Serialize(ret));

            }
        }
Ejemplo n.º 4
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;
            }
        }
        private void updateCollaborators(long cityId)
        {
            var newCollaborators = hdCollabValues.Value.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
            var currentCollaborators = hdCurrentCollabs.Value.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            List<long> removedEntities = new List<long>();
            List<long> addedEntities = new List<long>();

            foreach (var currentId in currentCollaborators)
            {
                if (!newCollaborators.Contains(currentId))
                {
                    //Entidade não é mais colaboradora
                    removedEntities.Add(Convert.ToInt64(currentId));
                }
            }

            foreach (var currentId in newCollaborators)
            {
                if (!currentCollaborators.Contains(currentId))
                {
                    //Entidade não é mais colaboradora
                    addedEntities.Add(Convert.ToInt64(currentId));
                }
            }

            if (addedEntities.Count > 0 || removedEntities.Count > 0)
            {
                //Adiciona o responsável para o período aberto
                long periodOpenId = 0;

                long.TryParse(Commons.SecurityUtils.descriptografar(hdOpenPeriodId.Value), out periodOpenId);

                if (periodOpenId > 0)
                {
                    using (Lib.Repositories.UserRepository ctx = new Lib.Repositories.UserRepository(this.ActiveUser))
                    {
                        ctx.updateCollaborators(addedEntities, removedEntities, periodOpenId, cityId);
                    }
                }
            }
        }
        private void removeResponsable(long cityId)
        {
            //Adiciona o responsável para o período aberto
            long periodOpenId = 0;

            long.TryParse(Commons.SecurityUtils.descriptografar(hdOpenPeriodId.Value), out periodOpenId);

            if (periodOpenId > 0)
            {
                using (Lib.Repositories.UserRepository ctx = new Lib.Repositories.UserRepository(this.ActiveUser))
                {
                    ctx.removeResponsable(periodOpenId, cityId);
                }
            }
        }
        private void loadEntities()
        {
            using (Lib.Repositories.UserRepository cont = new Lib.Repositories.UserRepository(this.ActiveUser))
            {
                var entities = cont.getAllAccreditedEntities();

                if (entities != null)
                {
                    var list = entities.Select(c => new
                    {
                        Id = c.Id,
                        Name = c.Name
                    }).ToList();

                    ddlCollaborator.DataSource = list;
                    ddlCollaborator.DataBind();
                    ddlCollaborator.Items.Insert(0, new ListItem(Resources.Label.select_a_collaborator, ""));

                    ddlResponsable.DataSource = list;
                    ddlResponsable.DataBind();
                    ddlResponsable.Items.Insert(0, new ListItem(Resources.Label.any_responsable_selected, ""));

                    if (list.Count > 0)
                    {
                        JavaScriptSerializer js = new JavaScriptSerializer();
                        hdCollabJson.Value = js.Serialize(list);
                    }

                }

            }
        }
        private void addResponsable(long userId, long cityId)
        {
            //Adiciona o responsável para o período aberto
            long periodOpenId = 0;

            long.TryParse(Commons.SecurityUtils.descriptografar(hdOpenPeriodId.Value), out periodOpenId);

            if (periodOpenId > 0)
            {
                using (Lib.Repositories.UserRepository ctx = new Lib.Repositories.UserRepository(this.ActiveUser))
                {
                    ctx.approveRequest(userId, periodOpenId, cityId, Lib.Enumerations.RequestType.RESPONSABLE);
                }
            }
        }
Ejemplo n.º 9
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                if (!userAuthenticate())
                {
                    throw new Exception(Resources.Message.user_not_allowed);
                }
                List<Lib.Entities.User> users = null;
                JavaScriptSerializer serializer = new JavaScriptSerializer();

                using (Lib.Repositories.UserRepository rep = new Lib.Repositories.UserRepository(this.ActiveUser))
                {
                    List<int> list = null;
                    if (!String.IsNullOrWhiteSpace(context.Request.Form["ut"]))
                    {
                        string[] filter = context.Request.Form["ut"].Split(',');
                        list = getUserTypes(filter);
                    }

                    bool? status = null;

                    if (!String.IsNullOrWhiteSpace(context.Request.Form["st"]))
                    {
                        var qStatus = context.Request.Form["st"].ToLower();

                        if (qStatus == "active")
                            status = true;
                        else if (qStatus == "inactive")
                            status = false;
                    }

                    users = rep.search(list, status);

                }

                if (this.ActiveUser.UserTypeEnum != Lib.Enumerations.UserType.Master)
                {
                    users = users.Where(f => f.UserTypeEnum != Lib.Enumerations.UserType.Master).ToList();
                }

                var result = users.Select(user => new
                {
                    Id = Commons.SecurityUtils.criptografar(user.Id.ToString()),
                    Name = user.Name,
                    Email = user.Email,
                    Type = Lib.Enumerations.EnumManager.getStringFromUserType(user.UserTypeEnum, user.Network),
                    AcceptedTerms = user.UserTypeEnum == Lib.Enumerations.UserType.Entity ? (user.TermsOfUse ? "1" : "0") : "-1",
                    Approved = user.Network ? (user.NetworkApproved ? "1" : "0") : "-1",
                    Nature = user.Nature,
                    Status = user.Active,
                    User = user.Login
                }).ToList();

                context.Response.ContentType = "application/json";
                context.Response.Write(serializer.Serialize(result));
            }
            catch (Exception ex)
            {
                Lib.Log.ErrorLog.saveError("Web.Handler.User.GetAll.ProcessRequest", ex);
                context.Response.StatusCode = 500;
                context.Response.Write(String.Format(Resources.Message.unknow_error, ex.Message));
            }
        }
Ejemplo n.º 10
0
 private void loadEntities()
 {
     using (Lib.Repositories.UserRepository repo = new Lib.Repositories.UserRepository(this.ActiveUser))
     {
         foreach(var item in repo.selectWhere(u => u.UserType == Lib.Enumerations.UserType.Entity && u.Entity.Network == true))
         {
             ddlEntidades.Items.Add(new ListItem(item.Name, item.Id.ToString()));
         }
     }
 }
Ejemplo n.º 11
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (chbCredenciada.Checked && chbTermsAccepted.Checked == false)
            {
                lblerroterms.Text = Resources.Message.agree_terms;
                return;
            }

            using (Lib.Repositories.UserRepository repository = new Lib.Repositories.UserRepository(this.ActiveUser))
            {
                Lib.Entities.User user = new Lib.Entities.User();
                user.Active = true;
                user.Email = txtemail.Text;
                user.Login = txtuser.Text;
                user.Name = txtname.Text;
                user.Password = Commons.SecurityUtils.criptografaSenha(txtconfirmpassword.Text);

                if (rbdEntity.Checked)
                {
                    user.UserType = (int)Lib.Enumerations.UserType.Entity;
                }
                else
                {
                    user.UserType = (int)Lib.Enumerations.UserType.Others;
                }

                user.Region = ddlRegion.SelectedValue;
                user.Area = txtArea.Text;
                user.Range = ddlAtuation.SelectedValue;
                user.Address = txtAddress.Text;
                user.Number = txtNumber.Text;
                user.Neighborhood = txtNeighborn.Text;
                user.Region = ddlRegion.SelectedValue;
                user.ZipCode = txtCep.Text;
                user.CityId = long.Parse(ddlCities.SelectedValue);
                user.Phone = txtPhone.Text;
                user.WebSite = txtSite.Text;
                user.Nature = ddlNature.SelectedValue;

                user.CNPJ = txtCnpj.Text ;
                user.ContactName = txtNomeRepresentante.Text;
                user.Organization = "";
                user.ContactEmail = txtEmailRepresentante.Text;

                user.Network = chbCredenciada.Checked;
                user.AcceptionTermsDate = DateTime.Now;
                user.TermsOfUse = true;

                MemoryStream ms = null;
                string mimeType = string.Empty;

                if (!String.IsNullOrWhiteSpace(fileUpload.PostedFile.FileName))
                {
                    if (imageIsValid(fileUpload.PostedFile.FileName))
                    {
                        ms = Lib.Utils.ImageUtils.redimensionarProporcionalmente(fileUpload.FileContent, 75);
                    }
                    else
                    {
                        lblErrorUpload.Text = Resources.Message.invalid_image_extension;
                        return;
                    }
                }
                else
                {
                    //Busca a imagem default do sistema
                    if (File.Exists(Server.MapPath("~/Design/Images/noavatar.png")))
                    {
                        System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("~/Design/Images/noavatar.png"));

                        System.Drawing.Image imageSized = null;
                        System.Drawing.Size size = new System.Drawing.Size(75, 75);
                        imageSized = new System.Drawing.Bitmap(image, size);

                        ms = new MemoryStream();
                        imageSized.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    }
                }

                if (ms != null)
                    user.Thumb = ms.ToArray();

                user.Mime = "image/png";

                repository.save(user);

                this.login(user, true);
            }
        }