Advertisement
Guest User

Untitled

a guest
May 4th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. namespace E_Learning.Models
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using E_Learning.Helpers;
  6.  
  7. public partial class users
  8. {
  9. public string getHandle()
  10. {
  11. return Slugify.Make(this.first_name + ' ' + this.last_name);
  12. }
  13.  
  14. public string full_name
  15. {
  16. get
  17. {
  18. return this.first_name + ' ' + this.last_name;
  19. }
  20. }
  21.  
  22. private Nullable<int> age
  23. {
  24. get
  25. {
  26. DateTime now = DateTime.Today;
  27.  
  28. if (this.birthday.HasValue)
  29. {
  30. DateTime birthday = DateTime.Parse(this.birthday.ToString());
  31. int age = now.Year - birthday.Year;
  32.  
  33. if (now < birthday.AddYears(age))
  34. age--;
  35.  
  36. return age;
  37. }
  38.  
  39. return null;
  40. }
  41. }
  42. }
  43. }
  44.  
  45. public ActionResult Index(Entities db)
  46. {
  47. string password = BCryptHelper.HashPassword("admin", BCryptHelper.GenerateSalt(8));
  48.  
  49. users user = new users
  50. {
  51. first_name = "Rafael",
  52. last_name = "Alexandre",
  53. email = "rafael.alexandre@voxdigital.com.br",
  54. password = password,
  55. };
  56.  
  57. user.handle = user.getHandle();
  58. db.Set<users>().Add(user);
  59. db.SaveChanges();
  60.  
  61. return View("~/Views/Index.cshtml");
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement