Ejemplo n.º 1
0
        public ActionResult EditEmailDataParsingRule(EditRuleForDataModel model)
        {
            var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id;

            if (ModelState.IsValid && IsUsersEmailDataParsingRule(userId, model.Id))
            {
                var table = tablesRepository.Find(t => t.AuthorId_Id == userId && t.Name.Equals(model.Cell.TableId));
                var rule = emailDataParsingRulesRepository.Find(w => w.Id == model.Id);
                var parentRule = emailParsingRulesRepository.Find(r => r.EmailDataParsingRulesModels.Where(c => c.Id == rule.Id).FirstOrDefault().Equals(rule));

                if (rule != null)
                {
                    var parentId = rule.EmailParsingRulesModels.Id;

                    rule.Expression = HttpUtility.HtmlEncode(model.Expression);
                    rule.IsRegexpExpression = model.IsRegexpExpression.Equals(CultureHelper.GetStringForCurentCulture("RegularExpression"));
                    rule.DataExploration = (int)Enum.Parse(typeof(DataExplorationEnums), model.DataExploration);
                    rule.DataExplorationExpression = HttpUtility.HtmlEncode(model.DataExplorationExpression);
                    rule.IsChanging = model.IsChanging.Equals("C");
                    rule.ExpressionToChange = HttpUtility.HtmlEncode(model.ExpressionToChange);
                    rule.RegularExpressionToChange = HttpUtility.HtmlEncode(model.RegularExpressionToChange);
                    rule.ChangeTo = HttpUtility.HtmlEncode(model.ChangeTo);
                    rule.TableId_Id = table.Id;
                    rule.Worksheet = Convert.ToInt32(model.Cell.Worksheet);
                    rule.Column =  (int)Enum.Parse(typeof(ColumnEnums), model.Cell.Column);
                    rule.ParsingMode = model.ParsingMode;
                    rule.ConsiderRegister = model.ConsiderRegister.Equals("C");
                    rule.Status = model.Status;
                    rule.IsUpdatingRule = parentRule.IsUpdatingRule;
                    // rule.IsUpdatindIndex = model.IsUpdatindIndex.Equals("C");
                    if (parentRule.IsUpdatingRule)
                    {
                        rule.ColumnForUpdate = (int)Enum.Parse(typeof(ColumnEnums), model.ColumnForUpdate);
                    }

                    emailDataParsingRulesRepository.Commit();

                    return RedirectToAction("EditEmailDataParsingRule", new { ruleId = rule.Id });
                }
            }

            return View();
        }
Ejemplo n.º 2
0
        public ActionResult EditEmailParsingRule(long ruleId)
        {
            var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id;

            if (IsUsersEmailParsingRule(userId, ruleId))
            {
                var rule = emailParsingRulesRepository.Find(w => w.Id == ruleId);

                var user = UserHelper.GetUserByEmail(User.Identity.Name);

                var tables =
                    tablesRepository.FindAll(w => w.AspNetUsers.Id.Equals(user.Id)).Select(l => l.Name).ToList();

                List<SelectListItem> worksheetsList = new List<SelectListItem>();

                for (int i = 0; i < 10; i++)
                {
                   // worksheetsList.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
                     worksheetsList.Add(new SelectListItem { Text = Enum.GetName(typeof(WorksheetsNames), i) + " worksheet", Value = i.ToString() });

                   // Enum.GetName(typeof(DataExplorationEnums), updatingRule.DataExploration)
                }

                List<SelectListItem> saveEmail = new List<SelectListItem>
                {
                    new SelectListItem {Text = "Email without attachments", Value = "0"},
                    new SelectListItem {Text = "Email with attachments", Value = "1"}
                };

                var saveEmailProperties = saveEmailPropertiesRepository.FindAll(w => w.EmailParsingRulesModelsId == ruleId && w.SaveEmailProp != null).ToList();

                if (rule != null)
                {
                    if (!rule.IsUpdatingRule)
                    {
                        var model = new EditRuleForEmailModel
                        {
                            Id = rule.Id,
                            Email = HttpUtility.HtmlDecode(rule.Email),
                            Subject = HttpUtility.HtmlDecode(rule.Subject),
                            PlainContains = HttpUtility.HtmlDecode(rule.PlainContains),
                            //IsUpdatingRule = rule.IsUpdatingRule.ToString(),
                            Name = rule.Name,
                            Tables = tables,
                            WorksheetsList = worksheetsList,
                            SaveEmail = saveEmail,
                            Status = rule.Status == null ? rule.Status = Model.Enums.RuleStatusEnums.Active.ToString() : rule.Status,
                            SaveEmailProperties = saveEmailProperties,
                            SaveEmailGroupItem = GetLayoutGroupForEmailParsingRule(rule.Id, tables, worksheetsList, saveEmail, rule.IsUpdatingRule, rule.CopyRuleFromPreviousOrder)
                        };
                        return PartialView(model);
                    }
                    else
                    {
                        var updatingRule = rule.EmailDataParsingRulesModels.Where(c => c.EmailParsingRulesModelsId_Id == rule.Id && c.IsUpdatindIndex).FirstOrDefault();
                        var table = tablesRepository.Find(t => t.Id == updatingRule.TableId_Id);

                        var updatingRuleModel = new EditRuleForDataModel();

                        if (updatingRule != null)
                        {
                            updatingRuleModel = new EditRuleForDataModel
                            {
                                Id = updatingRule.Id,
                                ParentId = rule.Id,
                                Expression = HttpUtility.HtmlDecode(updatingRule.Expression),
                                DataExplorationExpression = HttpUtility.HtmlDecode(updatingRule.DataExplorationExpression),
                                ExpressionToChange = HttpUtility.HtmlDecode(updatingRule.ExpressionToChange),
                                RegularExpressionToChange = HttpUtility.HtmlDecode(updatingRule.RegularExpressionToChange),
                                ChangeTo = HttpUtility.HtmlDecode(updatingRule.ChangeTo),
                                DataExploration = Enum.GetName(typeof(DataExplorationEnums), updatingRule.DataExploration),
                                IsUpdatindIndex = (updatingRule.IsUpdatindIndex).ToString(),
                                IsRegexpExpression = Convert.ToString(updatingRule.IsRegexpExpression),
                                IsChanging = Convert.ToString(updatingRule.IsChanging),
                                Status = updatingRule.Status == null ? rule.Status = Model.Enums.RuleStatusEnums.Active.ToString() : rule.Status,
                                ParsingMode = updatingRule.ParsingMode,
                                ConsiderRegister = (updatingRule.ConsiderRegister).ToString(),
                                IsUpdatingRule = false,
                                ColumnForUpdate = Convert.ToString(updatingRule.ColumnForUpdate)
                            };
                              if(table != null)
                                {
                                    updatingRuleModel.Cell = new CellModel { TableId = table.Name, Column = Convert.ToString(updatingRule.Column), Worksheet = Convert.ToString(updatingRule.Worksheet) };
                                }
                        }

                        var model = new EditUpdatingRuleForEmailModel
                        {
                            Id = rule.Id,
                            Email = HttpUtility.HtmlDecode(rule.Email),
                            Subject = HttpUtility.HtmlDecode(rule.Subject),
                            PlainContains = HttpUtility.HtmlDecode(rule.PlainContains),
                            Tables = tables,
                            WorksheetsList = worksheetsList,
                            Name = rule.Name,
                            SaveEmail = saveEmail,
                            Status = rule.Status == null ? rule.Status = Model.Enums.RuleStatusEnums.Active.ToString() : rule.Status,
                            SaveEmailProperties = saveEmailProperties,
                            SaveEmailGroupItem = GetLayoutGroupForEmailParsingRule(rule.Id, tables, worksheetsList, saveEmail, rule.IsUpdatingRule, rule.CopyRuleFromPreviousOrder),
                            UpdatingRule = updatingRuleModel
                        };
                        return PartialView("EditEmailParsingUpdatingRule", model);
                    }

                }
            }

            return RedirectToAction("ManageEmailParsingRules");
        }
Ejemplo n.º 3
0
        public ActionResult EditEmailDataParsingRule(long ruleId)
        {
            var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id;

            if (IsUsersEmailDataParsingRule(userId, ruleId))
            {
                var rule = emailDataParsingRulesRepository.Find(w => w.Id == ruleId);
                var parentRule = emailParsingRulesRepository.Find(r => r.EmailDataParsingRulesModels.Where(c => c.Id == rule.Id).FirstOrDefault().Equals(rule));
                var d = rule.TableId_Id;
                var d1 = rule.Worksheet;
                var d2 = rule.Column;
                var table = tablesRepository.Find(t => t.Id == rule.TableId_Id);

                if (rule != null)
                {
                    List<SelectListItem> worksheetsList = new List<SelectListItem>();
                    for (int i = 0; i < 10; i++)
                    {
                        worksheetsList.Add(new SelectListItem { Text = Enum.GetName(typeof(WorksheetsNames), i) + " worksheet", Value = i.ToString() });
                    }

                    var model = new EditRuleForDataModel
                    {
                        Id = rule.Id,
                        ParentId = parentRule.Id,
                        Expression = HttpUtility.HtmlDecode(rule.Expression),
                        DataExplorationExpression = HttpUtility.HtmlDecode(rule.DataExplorationExpression),
                        ExpressionToChange = HttpUtility.HtmlDecode(rule.ExpressionToChange),
                        RegularExpressionToChange = HttpUtility.HtmlDecode(rule.RegularExpressionToChange),
                        ChangeTo = HttpUtility.HtmlDecode(rule.ChangeTo),
                        Tables = new List<SelectListItem>(),
                        WorksheetsList = worksheetsList,
                        DataExploration = Enum.GetName(typeof(DataExplorationEnums), rule.DataExploration),
                        Cell = new CellModel { TableId = table.Name, Column = Convert.ToString(rule.Column), Worksheet = Convert.ToString(rule.Worksheet) },
                        IsUpdatindIndex = (rule.IsUpdatindIndex).ToString(),
                        IsRegexpExpression = Convert.ToString(rule.IsRegexpExpression),
                        IsChanging = Convert.ToString(rule.IsChanging),
                        Status = rule.Status == null ? rule.Status = Model.Enums.RuleStatusEnums.Active.ToString() : rule.Status,
                        ParsingMode = rule.ParsingMode,
                        IsUpdatingRule = parentRule.IsUpdatingRule,
                        Name = rule.Name,
                        ColumnForUpdate = Convert.ToString(rule.ColumnForUpdate),
                        ConsiderRegister = (rule.ConsiderRegister).ToString()
                    };

                    model.Tables.Add(new SelectListItem { Text = CultureHelper.GetStringForCurentCulture("EmailController_AddNewDataRuleForEmails_Select_table"), Value = "-1" });

                    var tables = tablesRepository.FindAll(w => w.AspNetUsers.Id.Equals(userId));

                    if (tables.Any())
                    {
                        foreach (var t in tables)
                        {
                            model.Tables.Add(new SelectListItem { Text = t.Name, Value = t.Id.ToString() });
                        }
                    }

                    return PartialView(model);
                }
            }

            return RedirectToAction("ManageEmailParsingRules");
        }