Guest User

Untitled

a guest
Nov 19th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. // POST: Client/Create
  2. // To protect from overposting attacks, please enable the specific properties you want to bind to, for
  3. // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
  4. [HttpPost]
  5. [ValidateAntiForgeryToken]
  6. public ActionResult Create([Bind(Include = "ClientID,AccountNumber,FirstName,MiddleName,LastName,NickName,DOB,GenderTypeID,FacilityID,StatusID,StartDate,StartTimeID,EndDate,EndTime,ResponsiblePartyID,DateAdded,AddedBy,DateChanged,ChangedBy,DestroyDate")] client__information client__information, HttpPostedFileBase upload)
  7. {
  8. if (ModelState.IsValid)
  9. {
  10. if (upload != null && upload.ContentLength > 0)
  11. {
  12. var avatar = new File
  13. {
  14. FileName = System.IO.Path.GetFileName(upload.FileName),
  15. FileType = FileType.Avatar,
  16. ContentType = upload.ContentType
  17. };
  18. using (var reader = new System.IO.BinaryReader(upload.InputStream))
  19. {
  20. avatar.Content = reader.ReadBytes(upload.ContentLength);
  21. }
  22. client__information.Files = new List<File> { avatar };
  23. }
  24. //Used on create-post to automatically add Date and Time into DateAdded column.
  25. client__information.DateAdded = DateTime.Now;
  26. db.client__information.Add(client__information);
  27. db.SaveChanges();
  28. return RedirectToAction("Index");
  29.  
  30. [HttpPost]
  31. [ValidateAntiForgeryToken]
  32. public ActionResult Edit([Bind(Include = "ClientID,AccountNumber,FirstName,MiddleName,LastName,NickName,DOB,GenderTypeID,FacilityID,StatusID,StartDate,StartTimeID,EndDate,EndTime,ResponsiblePartyID,AddedBy,DateChanged,ChangedBy,DestroyDate")] client__information client__information, HttpPostedFileBase upload)
  33. {
  34. if (ModelState.IsValid)
  35. {
  36. if (upload != null && upload.ContentLength > 0)
  37. {
  38. var avatar = new File
  39. {
  40. FileName = System.IO.Path.GetFileName(upload.FileName),
  41. FileType = FileType.Avatar,
  42. ContentType = upload.ContentType
  43. };
  44. using (var reader = new System.IO.BinaryReader(upload.InputStream))
  45. {
  46. avatar.Content = reader.ReadBytes(upload.ContentLength);
  47. }
  48. client__information.Files = new List<File> { avatar };
  49. }
  50. //Add to column DateChanged on Edit
  51. client__information.DateChanged = DateTime.Now;
  52. db.Entry(client__information).State = EntityState.Modified;
  53. db.SaveChanges();
  54. return RedirectToAction("Index");
Add Comment
Please, Sign In to add comment