You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

  1. using Microsoft.AspNet.Identity.EntityFramework;
  2. using Sevomin.Models;
  3. using Sevomin.Models.Helpers;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using System.Web.Mvc;
  7. using System.Linq;
  8. namespace Sevomin.WebFrontend.Controllers
  9. {
  10. [Authorize]
  11. public class AuthorizedController : BaseController
  12. {
  13. public AuthorizedController()
  14. : this(new SevominUserManager(new UserStore<User>(SevominDbContext.Current)))
  15. {
  16. }
  17. public AuthorizedController(SevominUserManager userManager)
  18. {
  19. UserManager = userManager;
  20. }
  21. public SevominUserManager UserManager { get; private set; }
  22. public async Task<ActionResult> GetResume(string userid = "", bool english = false)
  23. {
  24. if (string.IsNullOrWhiteSpace(userid))
  25. userid = (await UserManager.FindByNameAsync(User.Identity.Name)).Id;
  26. Dovomin user = await UserManager.FindByIdAsync(userid) as Dovomin;
  27. if (user == null)
  28. return HttpNotFound();
  29. if (!User.IsInRole("God"))
  30. {
  31. if (User.IsInRole("Dovomin"))
  32. {
  33. if (userid != user.Id)
  34. {
  35. return HttpNotFound();
  36. }
  37. else { }
  38. }
  39. else if (User.IsInRole("Avalin"))
  40. {
  41. Avalin avalin = (await UserManager.FindByNameAsync(User.Identity.Name)) as Avalin;
  42. bool showIt = avalin.Jobs.Any(j =>
  43. {
  44. bool ret = j.Applications.Any(c => c.DovominId == userid);
  45. return ret;
  46. });
  47. if (!showIt)
  48. return HttpNotFound();
  49. }
  50. }
  51. string path = Path.Combine(Server.MapPath("~/App_Data/resumes/"), english ? user.EnglishResume : user.PersianResume);
  52. string fileDownloadName = string.Format("{0} {1} Resume{2}", user.DisplayName, english ? "English" : "Persian", Path.GetExtension(path));
  53. return File(path, "application/octet-stream", fileDownloadName);
  54. }
  55. }
  56. }