public PopularLink GetPopularLinkById(int popularlinkId) { const string commandString = @"SELECT PopularLinkId, Title, Active,Link FROM PopularLinks WHERE PopularLinkId = @PopularLinkId"; using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); var command = GetCommand(commandString, connection, CommandType.Text); var obj = new PopularLink(); { command.Parameters.Add("@PopularLinkId", popularlinkId); { using (var reader = command.ExecuteReader()) { while (reader.Read()) { obj.PopularLinkId = (int)reader["PopularLinkId"]; obj.Title = (string)reader["Title"]; obj.Link = (string)reader["Link"]; obj.Active = Convert.ToBoolean(reader["Active"]); } } } } return(obj); } }
public List <PopularLink> GetAllPopularLinks() { const string commandString = @"SELECT PopularLinkId, Title, Active,Link FROM PopularLinks"; using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); var command = GetCommand(commandString, connection, CommandType.Text); var objlist = new List <PopularLink>(); { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var obj = new PopularLink(); obj.PopularLinkId = (int)reader["PopularLinkId"]; obj.Title = (string)reader["Title"]; obj.Link = (string)reader["Link"]; obj.Active = Convert.ToBoolean(reader["Active"]); objlist.Add(obj); } } } return(objlist); } }
public HttpResponseMessage UpdatePopularLink([FromBody] PopularLink postedData) { HttpResponseMessage response = null; try { PopularLink popLinkToBeUpdated; string title = string.Empty; using (EverestPortalContext readContext = new EverestPortalContext()) { popLinkToBeUpdated = readContext.PopularLinks.Where(x => x.popularLinkId.Equals(postedData.popularLinkId)).FirstOrDefault <PopularLink>(); title = popLinkToBeUpdated.popularLinkTitle; } if (popLinkToBeUpdated != null) { popLinkToBeUpdated.popularLinkTitle = postedData.popularLinkTitle; popLinkToBeUpdated.popularLinkDescription = postedData.popularLinkDescription; popLinkToBeUpdated.popularLinkDisplayOrder = postedData.popularLinkDisplayOrder; } using (EverestPortalContext updateContext = new EverestPortalContext()) { updateContext.Entry(popLinkToBeUpdated).State = System.Data.Entity.EntityState.Modified; updateContext.SaveChanges(); } if (title != postedData.popularLinkTitle) { string filePath = string.Empty, newFilePath = string.Empty; if (ConfigurationManager.AppSettings["PopularLinks"] != null) { string popularLinksFolder = ConfigurationManager.AppSettings["PopularLinks"].ToString(); filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath.Replace("API", "Web") + popularLinksFolder; System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(filePath); var file = dirInfo.GetFiles().Where(x => x.Name == title + x.Extension).FirstOrDefault(); if (filePath != null && System.IO.File.Exists(filePath + @"\" + title + file.Extension)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath + @"\" + title + file.Extension); fileInfo.CopyTo(filePath + @"\" + postedData.popularLinkTitle + file.Extension); fileInfo.Delete(); } } } //response = Request.CreateResponse<CADPage>(HttpStatusCode.OK,Request.RequestUri.ToString()); response = Request.CreateResponse <PopularLink>(HttpStatusCode.OK, postedData); } catch (Exception ex) { } return(response); }
public ActionResult ChangeLinkStatus(int LinkId, bool Value) { PopularLink obj = new PopularLink(); obj = _adminRepository.GetPopularLinkById(LinkId); if (obj != null) { obj.Active = Value; } _adminRepository.UpdateLinkStatus(obj); return(Json(new { Message = " Popular Link Status Changed Successfully", Success = true })); }
public ActionResult SavePopularLink(PopularLink popularlink) { if (Request.Form["PopularLinkId"] == "0") { _adminRepository.AddPopularLink(popularlink); } else { _adminRepository.UpdatePopularLink(popularlink); } PopularLinkModel obj = new PopularLinkModel(); obj.plinks = _adminRepository.GetAllPopularLinks(); return(View("ManagePopularLinks", obj)); }
public void UpdateLinkStatus(PopularLink popularlink) { const string commandString = @"Update PopularLinks SET Active = @Active WHERE PopularLinkId=@PopularLinkId"; try { using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); var command = new SqlCommand(commandString, connection); command.Parameters.Add("@PopularLinkId", popularlink.PopularLinkId); command.Parameters.Add("@Active", popularlink.Active); command.ExecuteNonQuery(); } } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public void AddPopularLink(PopularLink popularlink) { const string commandString = @"INSERT INTO PopularLinks (Title,Active,Link) VALUES (@Title,@Active,@Link)"; try { using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); var command = new SqlCommand(commandString, connection); command.Parameters.Add("@Title", popularlink.Title); command.Parameters.Add("@Link", popularlink.Link); command.Parameters.Add("@Active", popularlink.Active); command.ExecuteNonQuery(); } } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public HttpResponseMessage AddPopularLink([FromBody] PopularLink postedData) { HttpResponseMessage response = null; try { PopularLink newPopLink = new PopularLink(); newPopLink.popularLinkTitle = postedData.popularLinkTitle; newPopLink.popularLinkDescription = postedData.popularLinkDescription; using (EverestPortalContext context = new EverestPortalContext()) { context.PopularLinks.Add(newPopLink); context.SaveChanges(); } response = Request.CreateResponse <PopularLink>(HttpStatusCode.Created, newPopLink); } catch (Exception ex) { } return(response); }