protected void btnAdd_OnClick(object sender, EventArgs e) { grid.InnerHtml = ""; lblMsg.Text = ""; using (var dataContext = new EPGDataModel()) { var source = new SourceURL { Url = txtSourceURLAdd.Text, Type=ddlSourceType.SelectedValue, IsActive = true, EntryDate = DateTime.Today, EntryId = Convert.ToString(Session["USER_KEY"]), EntryIP = CommonFunctions.GetIpAddress() }; dataContext.SourceURLs.Add(source); dataContext.SaveChanges(); source.ActiveChannels = GetActiveChannels(source.Url, source.Srno); dataContext.SaveChanges(); } lblMsg.Text = "Record added successfully!"; BindGrid(); }
protected void btnImport_OnClick(object sender, EventArgs e) { if (fileUploadCtl.HasFile) { var fileName = Path.GetFileName(fileUploadCtl.FileName); fileUploadCtl.PostedFile.SaveAs(Server.MapPath(@"../ImportedList/"+fileName)); var lines = File.ReadAllText(Server.MapPath(@"../ImportedList/" + fileName)); var listOfUrls = lines.Split(','); foreach (var url in listOfUrls) { string type = string.Empty; switch (url.Substring(url.LastIndexOf('.'), 4).ToLower()) { case ".zip": type = "Zip"; break; case ".xml": type = "Xml"; break; } var sourceUrl = new SourceURL { Url = url, Type = type, EntryIP= CommonFunctions.GetIpAddress(), EntryDate = DateTime.Today, IsActive= true, EntryId = Convert.ToString(Session["USER_KEY"]), }; try { using (var dataContext = new EPGDataModel()) { dataContext.SourceURLs.Add(sourceUrl); dataContext.SaveChanges(); sourceUrl.ActiveChannels = GetActiveChannels(sourceUrl.Url, sourceUrl.Srno); dataContext.SaveChanges(); } } catch (Exception ex) { lblMsg.Text = "One or more Urls in text files already exsists in database."; } } lblMsg.Text = "List Imported successfully!"; BindGrid(); } }