fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6.  
  7. namespace MvcApplication6.Controllers
  8. {
  9. public class ContractsController : Controller
  10. {
  11. //
  12. // GET: /Contracts
  13.  
  14. public ActionResult Index()
  15. {
  16. return RedirectToAction("Inbox");
  17. }
  18.  
  19. //
  20. // GET: /Contracts/Indox
  21.  
  22. public ActionResult Inbox()
  23. {
  24. if (Request.Cookies["session-id"] == null)
  25. {
  26. Response.Redirect("/");
  27. return null;
  28. }
  29.  
  30. List<Models.ContractPlain> currentContracts = new List<Models.ContractPlain>();
  31.  
  32. try
  33. {
  34. int currentUserId = GetUserIdBinding(Request.Cookies["user-name"].Value);
  35.  
  36. foreach (var item in GetObjectData())
  37. {
  38. if (item.recv_id == currentUserId)
  39. {
  40. var record = new Models.ContractPlain
  41. {
  42. Id = item.id,
  43. ContractGuid = Guid.Parse(item.guid),
  44. Sender = GetLoginBinding(Convert.ToInt32(item.sender_id)),
  45. Receiver = GetLoginBinding(Convert.ToInt32(item.recv_id)),
  46. ContractType = Convert.ToInt32(item.type),
  47. ContractStatus = item.status,
  48. CreatedTime = DateTime.Parse(item.date_created),
  49. CreditEnd = DateTime.Parse(item.date_credit_end)
  50. };
  51.  
  52. currentContracts.Add(record);
  53. }
  54. }
  55. }
  56. catch (Exception exc)
  57. {
  58. exc.ToString();
  59. }
  60.  
  61. return View(currentContracts);
  62. }
  63.  
  64. System.Data.Objects.ObjectSet<contract> GetObjectData()
  65. {
  66. MySqlEntities db = new MySqlEntities();
  67. return db.contracts;
  68. }
  69.  
  70. int GetUserIdBinding(string login)
  71. {
  72. MySqlEntities db = new MySqlEntities();
  73. return Convert.ToInt32(db.GetUserIdByLogin(login).FirstOrDefault());
  74. }
  75.  
  76. string GetLoginBinding(int value)
  77. {
  78. MySqlEntities db = new MySqlEntities();
  79. return db.GetLoginByUserId(value).FirstOrDefault();
  80. }
  81. }
  82. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty