// // GET: /Component/ public ActionResult Index(int? componentid) { var myComponentDataUtil = new ComponentDataUtil(); var myComponents = new Components(); var selectedComponent = new Component(); var sortedList = new List<Component>(); foreach (var component in myComponentDataUtil.GetAllComponents()) { myComponents._components.Add(component); } foreach (var component in myComponents._components) { if (component.ComponentID == componentid) selectedComponent = component; } foreach (var component in myComponents._components) { if (selectedComponent.ComponentName==component.ComponentName) sortedList.Add(component); } if (sortedList.Count > 0) { ViewData["AvailableQuantity"] = myComponents.GetAvailableQuantity(sortedList[0].ComponentName); return View(sortedList[0]); } return View(); }
// // GET: /Component/ public ActionResult Index(int? componentid) { var myComponentDataUtil = new ComponentDataUtil(); var myComponents = new Components(); var selectedComponent = new Component(); var userCommentsList = new List<MvcHtmlString>(); var sortedList = new List<Component>(); var emptylist = new List<MvcHtmlString>(); LoanDataUtil ldu = new LoanDataUtil(); myComponents._LoanInformations = ldu.GetAllLoanInformation(); foreach (var component in myComponentDataUtil.GetAllComponents()) { myComponents._components.Add(component); } foreach (var component in myComponents._components) { if (component.ComponentID == componentid) selectedComponent = component; } foreach (var component in myComponents._components) { if (selectedComponent.ComponentName==component.ComponentName) sortedList.Add(component); } foreach (var component in sortedList) { if (!String.IsNullOrEmpty(component.UserComment)) userCommentsList.Add(MvcHtmlString.Create(HttpUtility.HtmlEncode(component.UserComment + "\n\n Skrevet omkring komponent nummer: " + component.ComponentNumber).Replace("\n", "<br />"))); } if (userCommentsList.Count < 1) { emptylist.Add(MvcHtmlString.Create(HttpUtility.HtmlEncode("Ingen kommentarer fundet"))); ViewData["UserComments"] = emptylist; } else { ViewData["UserComments"] = userCommentsList.Distinct().ToList(); } if (sortedList.Count > 0) { ViewData["AvailableQuantity"] = myComponents.GetAvailableQuantity(sortedList[0].ComponentName); return View(sortedList[0]); } ViewData["AvailableQuantity"] = 0; return View(); }
public ActionResult Remove(Component component) { var loanDataUtil = new LoanDataUtil(); var loanInfo = loanDataUtil.GetLoanInformation(component); if (Session["User"] == null) return RedirectToAction("Index", "Home"); if (Session["User"].ToString() == loanInfo.ReservationID) { loanDataUtil.RemoveReservation(component.ComponentID); } return RedirectToAction("Reserve","Account"); }
// // GET: /Home/ public ActionResult Index(string searchString, string category, int? page) { var componentsPerPage = new int?(); var mySearcher = new Searcher(); var myComponentDataUtil = new ComponentDataUtil(); var myComponents = new Components(); var emptyComponent = new Component(); var listOfQuantity = new List<int>(); emptyComponent.ComponentName="Ingen Komponenter Fundet"; componentsPerPage = 20; // Tjekker om der er indtastet en søgning, hvis ja, hentes en komponentliste med de indtastede tags if (!String.IsNullOrEmpty(searchString)) { var SearchTags = mySearcher.SplitString(searchString); foreach (var component in myComponentDataUtil.GetComponents(SearchTags)) { myComponents._components.Add(component); } } else { //Tjekker om man har trykket på en kategori, hvis ja, hentes en komponentliste med den kategori if (!String.IsNullOrEmpty(category)) { foreach (var component in myComponentDataUtil.GetAllComponents()) { if (component.Category == category) myComponents._components.Add(component); } } else { foreach (var component in myComponentDataUtil.GetAllComponents()) { myComponents._components.Add(component); } } } //Opretter liste med alle kategorier var listOfCategories=myComponents.GetAllCategories(); //Sætter listen med kategorier i alfabetisk rækkefølge listOfCategories.Sort(); //Opretter liste til hvis der ikke eksisterer nogen kategorier var noneFound= new List<string> {"Ingen kategorier fundet"}; if (listOfCategories.Count != 0) ViewData["Categories"] = listOfCategories; else ViewData["Categories"] = noneFound; //Sorterer listen med komponenter, så den er i alfabetisk rækkefølge og komponenterne kun ankommer en gang. var sortedList = myComponents._components.OrderBy(c => c.ComponentName).DistinctBy(c => c.ComponentName).ToList(); //Udregner hvor mange sider, der skal være på hjemmesiden ViewData["NumberOfPages"] = (sortedList.Count + componentsPerPage - 1) / componentsPerPage; //Udregner hvor mange der er af hver komponent type(taget ud af Componentname), lægger det derefter over i en ny liste foreach (var component in sortedList) { listOfQuantity.Add(myComponents.GetAvailableQuantity(component.ComponentName)); } //Hvis dette tjek går igennem, er der ikke nok komponenter til at vise den ønskede side if (((componentsPerPage * page.GetValueOrDefault())) >= sortedList.Count || page < 0) { myComponents._components.Clear(); myComponents._components.Add(emptyComponent); listOfQuantity.Clear(); listOfQuantity.Add(0); return View(myComponents._components); } ViewData["AvailableQuantity"] = listOfQuantity; //Hvis dette tjek går igennem har man komponenter til overs, men ikke nok til at lave en "hel" side if(((componentsPerPage*page.GetValueOrDefault())+componentsPerPage)>sortedList.Count) return View(sortedList.GetRange((page * componentsPerPage).GetValueOrDefault(), sortedList.Count - (componentsPerPage * page).GetValueOrDefault())); //Returnerer componentsPerPage, startende fra den side man er kommet til return View(sortedList.GetRange(((page * componentsPerPage).GetValueOrDefault()), componentsPerPage.GetValueOrDefault())); }
public bool CreateLoanInformation(LoanInformation loan, Component c) { try { // Open the connection _conn.Open(); // prepare command string using paramters in string and returning the given identity string insertStringParam = @"INSERT INTO [LoanInformation] (Component, AdminComment, UserComment, LoanDate, ReturnDate) OUTPUT INSERTED.LoanID VALUES (@Data1, @Data2,@Data3,@Data4,@Data5)"; object adminCommentParam = DBNull.Value; object userCommentParam = DBNull.Value; object loanDateParam = DBNull.Value; object returnDateParam = DBNull.Value; loan.Component = c.ComponentID; using (SqlCommand cmd = new SqlCommand(insertStringParam, _conn)) { // Get your parameters ready cmd.Parameters.Add(cmd.CreateParameter()).ParameterName = "@Data1"; cmd.Parameters.Add(cmd.CreateParameter()).ParameterName = "@Data2"; cmd.Parameters.Add(cmd.CreateParameter()).ParameterName = "@Data3"; cmd.Parameters.Add(cmd.CreateParameter()).ParameterName = "@Data4"; cmd.Parameters.Add(cmd.CreateParameter()).ParameterName = "@Data5"; cmd.Parameters["@Data1"].Value = loan.Component; cmd.Parameters["@Data2"].Value = loan.AdminComment ?? adminCommentParam; cmd.Parameters["@Data3"].Value = loan.UserComment ?? userCommentParam; cmd.Parameters["@Data4"].Value = loan.LoanDate ?? loanDateParam; cmd.Parameters["@Data5"].Value = loan.ReturnDate ?? returnDateParam; //var id loan.LoanID = (int) cmd.ExecuteScalar(); //Returns the identity of the new tuple/record //hv.HID = (int)cmd.ExecuteNonQuery(); //Does not workReturns row affected and not the identity of the new tuple/record CurrentLoanInformation = loan; } } catch (Exception e) { Console.WriteLine(e.Message); return false; } finally { // Close the connection if (_conn != null) { _conn.Close(); } } return true; }
public LoanInformation GetLoanInformation(Component cp) { SqlDataReader rdr = null; try { // Open the connection _conn.Open(); // prepare command string using paramters in string and returning the given identity string insertStringParam = @"SELECT * FROM LoanInformation WHERE (Component = @Data1)"; SqlCommand cmd = new SqlCommand(insertStringParam, _conn); cmd.Parameters.Add(cmd.CreateParameter()).ParameterName = "@Data1"; cmd.Parameters["@Data1"].Value = cp.ComponentID; cmd.ExecuteNonQuery(); using (rdr = cmd.ExecuteReader()) { while (rdr.Read()) { var loanInfo = new LoanInformation(); loanInfo.LoanID = (int) rdr["LoanID"]; loanInfo.Component = (int) rdr["Component"]; if (rdr["AdminComment"] != DBNull.Value) loanInfo.AdminComment = (string)rdr["AdminComments"]; else { loanInfo.AdminComment = DBNull.Value.ToString(CultureInfo.InvariantCulture); } if (rdr["UserComment"] != DBNull.Value) loanInfo.UserComment = (string)rdr["UserComments"]; else { loanInfo.UserComment = DBNull.Value.ToString(CultureInfo.InvariantCulture); } if (rdr["LoanDate"] != DBNull.Value) loanInfo.LoanDate = (string)rdr["LoanDate"]; else { loanInfo.LoanDate = DBNull.Value.ToString(CultureInfo.InvariantCulture); } if (rdr["ReturnDate"] != DBNull.Value) loanInfo.ReturnDate = (string)rdr["ReturnDate"]; else { loanInfo.ReturnDate = DBNull.Value.ToString(CultureInfo.InvariantCulture); } CurrentLoanInformation = loanInfo; } } } catch (Exception e) { Console.WriteLine(e.Message); } return CurrentLoanInformation; }