public ActionResult XMLOperation(FormCollection formCollection, HttpPostedFileBase file) { string Result = ""; Indicator indicator = DatabaseObject.db.Indicators.Find(ConvertHelper.Convert <int>(formCollection["ID"], 0)); if (file != null) { string path = Server.MapPath(string.Format("~/Uploads/SiteSettings/{0}_{1}", indicator.Abbreviation, indicator.ID.ToString())); //file.SaveAs(path); try { XDocument document = XDocument.Load(new System.IO.StreamReader(file.InputStream)); document.Save(path); bool result = CrawlerHelper.CreateXML(indicator.ID, indicator.IndexUrl, indicator.Abbreviation, path); if (result) { Result = ITS.Resources.ResourcesFiles.MapLabel.FileError; } } catch (Exception e) { Result = ITS.Resources.ResourcesFiles.MapLabel.FileError; } } ViewBag.FileMsg = Result; return(View(indicator)); }
public ActionResult Form(Indicator indicator, FormCollection formCollection) { ViewBag.PublisherID = new SelectList(DatabaseObject.db.Publishers.Where(P => (Resources.ResourcesFiles.MapLabel.LookUpName == "Name_E" && !string.IsNullOrEmpty(P.Name_E)) || (Resources.ResourcesFiles.MapLabel.LookUpName == "Name_A" && !string.IsNullOrEmpty(P.Name_A))), "ID", Resources.ResourcesFiles.MapLabel.LookUpName); ViewBag.PeriodicityID = new SelectList(DatabaseObject.db.Periodicities.Where(P => (Resources.ResourcesFiles.MapLabel.LookUpName == "Name_E" && !string.IsNullOrEmpty(P.Name_E)) || (Resources.ResourcesFiles.MapLabel.LookUpName == "Name_A" && !string.IsNullOrEmpty(P.Name_A))), "ID", Resources.ResourcesFiles.MapLabel.LookUpName); indicator.Active = formCollection["active"] == "on" ? 1 : 0; indicator.Focus = formCollection["focus"] == "on" ? 1 : 0; if (ModelState["Focus"] != null) { ModelState["Focus"].Errors.Clear(); } if (ModelState["Active"] != null) { ModelState["Active"].Errors.Clear(); } if (ModelState["StartMonth"] != null) { ModelState["StartMonth"].Errors.Clear(); indicator.StartMonth = GetCurrentDate(formCollection["StartMonth"]); } if (ModelState["EndMonth"] != null) { ModelState["EndMonth"].Errors.Clear(); indicator.EndMonth = GetCurrentDate(formCollection["EndMonth"]); } if (ModelState.IsValid) { if (indicator.ID <= 0) { indicator.OwnerID = LoginToken.LoginUser.ID; indicator.CreateDate = DateTime.Now; DatabaseObject.db.Indicators.Add(indicator); DatabaseObject.db.SaveChanges(); XmlHelper.InsertXmlValue(indicator.IndicatorData("اضافة", "Add"), Server.MapPath("~/App_Data/Log/ITS_LOG_Indicator.xml"), "Operation"); bool result = CrawlerHelper.CreateXML(indicator.ID, indicator.IndexUrl, indicator.Abbreviation); if (Request["Form"] == Resources.ResourcesFiles.MapLabel.SaveAdd) { return(RedirectToAction("Add")); } else if (Request["Form"] == Resources.ResourcesFiles.MapLabel.Save) { return(RedirectToAction(Functions.FunctionName_Browse, new { times = 1 })); } } else { Indicator i = DatabaseObject.db.Indicators.Find(indicator.ID); i.ModifierID = LoginToken.LoginUser.ID; i.ModifyDate = DateTime.Now; i.Name_A = indicator.Name_A; i.Name_E = indicator.Name_E; i.ReportName_A = indicator.ReportName_A; i.ReportName_E = indicator.ReportName_E; i.Description_A = indicator.Description_A; i.Description_E = indicator.Description_E; i.Notes_A = indicator.Notes_A; i.Notes_E = indicator.Notes_E; i.WebsiteUrl = indicator.WebsiteUrl; i.IndexUrl = indicator.IndexUrl; i.Abbreviation = indicator.Abbreviation; i.StartMonth = indicator.StartMonth; i.EndMonth = indicator.EndMonth; i.PublisherID = indicator.PublisherID; i.PeriodicityID = indicator.PeriodicityID; i.SortIndex = indicator.SortIndex; i.Focus = indicator.Focus; i.Active = indicator.Active; DatabaseObject.db.Entry(i).State = EntityState.Modified; DatabaseObject.db.SaveChanges(); XmlHelper.InsertXmlValue(i.IndicatorData("تعديل", "Edit"), Server.MapPath("~/App_Data/Log/ITS_LOG_Indicator.xml"), "Operation"); if (Request["Form"] == Resources.ResourcesFiles.MapLabel.SaveEdit) { return(RedirectToAction("Edit", new { ID = indicator.ID })); } else if (Request["Form"] == Resources.ResourcesFiles.MapLabel.Save) { return(RedirectToAction(Functions.FunctionName_Browse, new { times = 1 })); } } } return(View(indicator)); }