Guest User

Untitled

a guest
Jul 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. The class is used in MVCnamespace Storage.Models
  2. {
  3. public class Topic : TableServiceEntity
  4. {
  5. [DisplayName("Partition Key")]
  6. public override string PartitionKey { get; set; }
  7. [DisplayName("Row Key")]
  8. public override string RowKey { get; set; }
  9. [DisplayName("Description")]
  10. public string Description { get; set; }
  11. public DateTime Created { get; set; }
  12. public DateTime Modified { get; set; }
  13. public String CreatedBy { get; set; }
  14. public string ModifiedBy { get; set; }
  15. }
  16. }
  17.  
  18. public ActionResult Create(MyCreateViewModel viewModel)
  19. {
  20. if (ModelState.IsValid)
  21. {
  22. viewModel.Entity.Created = DateTime.UtcNow;
  23. _myService.Insert(viewModel.Entity);
  24. _myService.SaveChanges();
  25. return this.RedirectToAction(x => x.Index());
  26. } else {
  27. PopulateViewModel(viewModel);
  28. return View(viewModel);
  29. }
  30. }
  31.  
  32. public ActionResult Edit(MyEditViewModel viewModel)
  33. {
  34. if (ModelState.IsValid)
  35. {
  36. viewModel.Entity.LastEditDate= DateTime.UtcNow;
  37. _myService.AttachAndUpdate(viewModel.Entity);
  38. _myService.SaveChanges();
  39. return this.RedirectToAction(x => x.Index());
  40. } else {
  41. PopulateViewModel(viewModel);
  42. return View(viewModel);
  43. }
  44. }
  45.  
  46. public class Topic
  47. {
  48. public Topic()
  49. {
  50. this.Created = DateTime.Now;
  51. this.CreatedBy = UserName;
  52. }
  53. [DisplayName("Partition Key")]
  54. public override string PartitionKey { get; set; }
  55. [DisplayName("Row Key")]
  56. public override string RowKey { get; set; }
  57. [DisplayName("Description")]
  58. public string Description { get; set; }
  59. public DateTime Created { get; set; }
  60. public DateTime Modified { get; set; }
  61. public String CreatedBy { get; set; }
  62. public string ModifiedBy { get; set; }
  63. }
Add Comment
Please, Sign In to add comment