PageRenderTime 57ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/IsaapNew/Isaap.UI/Api/CEOController.cs

https://gitlab.com/justbediego/Isaap
C# | 204 lines | 202 code | 1 blank | 1 comment | 1 complexity | 9c8901711d4d52dd12fe491c9a33f560 MD5 | raw file
  1. using Isaap.Core.Business;
  2. using Isaap.Core.DataAccess;
  3. using Isaap.UI.Api.Config;
  4. using Isaap.UI.Api.Models;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Net.Http;
  11. using System.Net.Http.Headers;
  12. using System.Threading.Tasks;
  13. using System.Web.Http;
  14. namespace Isaap.UI.Api
  15. {
  16. public class CEOController : ApiController
  17. {
  18. private IsaapContext dbContext;
  19. private CEOBusiness ceoBusiness;
  20. private AuthenticationController authenticationController;
  21. public CEOController()
  22. {
  23. dbContext = new IsaapContext();
  24. ceoBusiness = new CEOBusiness(dbContext);
  25. authenticationController = new AuthenticationController();
  26. }
  27. [LoggerIgnoreJsonData("Password")]
  28. public void Register(UserRegisterDTO model)
  29. {
  30. HttpClient client = new HttpClient();
  31. Dictionary<string, string> postData = new Dictionary<string, string> {
  32. { "secret", "6LdVGCAUAAAAAP4HIDkp9xT6pBlkwYHz2eAFdXIK" },
  33. { "response", model.Captcha },
  34. //{"remoteip", HttpContext.Current.Request.UserHostAddress }
  35. };
  36. var postResponse = client.PostAsync("https://www.google.com/recaptcha/api/siteverify", new FormUrlEncodedContent(postData)).Result;
  37. var responseString = postResponse.Content.ReadAsStringAsync().Result;
  38. recaptchaResponse googleResponse = JsonConvert.DeserializeObject<recaptchaResponse>(responseString);
  39. if (!googleResponse.success)
  40. throw new Exception("کد امنیتی مورد تایید نیست");
  41. ceoBusiness.Register(model.CompanyCode, model.NationalCode, model.FirstName, model.LastName, model.Username, model.Password, model.Email, model.Mobile);
  42. }
  43. [Authorize]
  44. [HttpPost]
  45. public void ModifyBasicInfo(ChangePersonInfoDTO model)
  46. {
  47. ceoBusiness.ModifyBasicInfo(authenticationController.GetUsername(), model.FirstName, model.LastName, model.FatherName, (Core.Model.Person.Person.GenderType)model.Gender, model.ShenasnameNo, model.NationalCode, model.BirthDate, model.PlaceOfBirth, (Core.Model.Person.Person.MaritalStates)model.MaritalStatus, (Core.Model.Person.Person.MilitaryServiceStates)model.MilitaryServiceStates, model.ReasonOfExemption);
  48. }
  49. [Authorize]
  50. [HttpPost]
  51. public void ModifyContactInfo(ChangeContactInfoDTO model)
  52. {
  53. ceoBusiness.ModifyContactInfo(authenticationController.GetUsername(), model.Mobile, model.Email, model.CountyID, model.Address, model.PostalCode, model.Phone);
  54. }
  55. [Authorize]
  56. [HttpGet]
  57. public object GetBasicInfo()
  58. {
  59. return ceoBusiness.GetBasicInfo(authenticationController.GetUsername());
  60. }
  61. [Authorize]
  62. [HttpGet]
  63. public object GetContactInfo()
  64. {
  65. return ceoBusiness.GetContactInfo(authenticationController.GetUsername());
  66. }
  67. [Authorize]
  68. [HttpGet]
  69. public HttpResponseMessage GetImage(int ID, int width = -1, int height = -1)
  70. {
  71. var image = ceoBusiness.GetImage(authenticationController.GetUsername(), ID, height, width);
  72. HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
  73. response.Content = new ByteArrayContent(image.FileData);
  74. response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
  75. response.Content.Headers.Add("Content-Disposition", "attachment; filename=\"" + image.Filename.Replace("\"", "") + "\"");
  76. return response;
  77. }
  78. [Authorize]
  79. [HttpGet]
  80. public object GetPictures()
  81. {
  82. return ceoBusiness.GetPictures(authenticationController.GetUsername());
  83. }
  84. [Authorize]
  85. [HttpPost]
  86. public void RemovePhotoScan()
  87. {
  88. ceoBusiness.RemovePhotoScan(authenticationController.GetUsername());
  89. }
  90. [Authorize]
  91. [HttpGet]
  92. public object GetDashboardData()
  93. {
  94. return ceoBusiness.GetDashboardData(authenticationController.GetUsername());
  95. }
  96. [Authorize]
  97. [HttpPost]
  98. public void RemoveShenasnameScan(DeleteObjectDTO model)
  99. {
  100. ceoBusiness.RemoveShenasnameScan(authenticationController.GetUsername(), model.ObjectID);
  101. }
  102. [Authorize]
  103. [HttpPost]
  104. public void RemoveNationalCardScan(DeleteObjectDTO model)
  105. {
  106. ceoBusiness.RemoveNationalCardScan(authenticationController.GetUsername(), model.ObjectID);
  107. }
  108. [Authorize]
  109. [HttpPost]
  110. public void RemoveInsuranceScan(DeleteObjectDTO model)
  111. {
  112. ceoBusiness.RemoveInsuranceScan(authenticationController.GetUsername(), model.ObjectID);
  113. }
  114. [Authorize]
  115. [HttpPost]
  116. public async Task ChangePhotoScan()
  117. {
  118. var provider = await Request.Content.ReadAsMultipartAsync();
  119. var file = provider.Contents[0];
  120. ceoBusiness.ChangePhotoScan(authenticationController.GetUsername(), file.Headers.ContentDisposition.FileName, file.ReadAsByteArrayAsync().Result);
  121. }
  122. [Authorize]
  123. [HttpPost]
  124. public async Task AddShenasnameScan()
  125. {
  126. var provider = await Request.Content.ReadAsMultipartAsync();
  127. var file = provider.Contents[0];
  128. ceoBusiness.AddShenasnameScan(authenticationController.GetUsername(), file.Headers.ContentDisposition.FileName, file.ReadAsByteArrayAsync().Result);
  129. }
  130. [Authorize]
  131. [HttpPost]
  132. public async Task AddNationalCardScan()
  133. {
  134. var provider = await Request.Content.ReadAsMultipartAsync();
  135. var file = provider.Contents[0];
  136. ceoBusiness.AddNationalCardScan(authenticationController.GetUsername(), file.Headers.ContentDisposition.FileName, file.ReadAsByteArrayAsync().Result);
  137. }
  138. [Authorize]
  139. [HttpPost]
  140. public async Task AddInsuranceScan()
  141. {
  142. var provider = await Request.Content.ReadAsMultipartAsync();
  143. var file = provider.Contents[0];
  144. ceoBusiness.AddInsuranceScan(authenticationController.GetUsername(), file.Headers.ContentDisposition.FileName, file.ReadAsByteArrayAsync().Result);
  145. }
  146. [Authorize]
  147. [HttpPost]
  148. public async Task AddTPCScan()
  149. {
  150. var provider = await Request.Content.ReadAsMultipartAsync();
  151. var file = provider.Contents[0];
  152. ceoBusiness.AddTPCScan(authenticationController.GetUsername(), file.Headers.ContentDisposition.FileName, file.ReadAsByteArrayAsync().Result);
  153. }
  154. [Authorize]
  155. [HttpPost]
  156. public void RemoveTPCScan(DeleteObjectDTO model)
  157. {
  158. ceoBusiness.RemoveTPCScan(authenticationController.GetUsername(), model.ObjectID);
  159. }
  160. [Authorize]
  161. [HttpPost]
  162. public void ModifyWorkshopInfo(ChangeWorkshopInfo model)
  163. {
  164. ceoBusiness.ModifyWorkshopInfo(authenticationController.GetUsername(), model.UnitName, model.WorkshopSize, model.CompanyCode, model.NightWorkersNo, model.MorningWorkersNo, model.SafetyWorkersNo, model.MaleWorkersNo, model.EveningWorkersNo, model.FemaleWorkersNo, model.FieldOfActivityId, model.ProductionTypeId, model.TechnicalProtectionCommittee, model.SocialSecurityCode);
  165. }
  166. [Authorize]
  167. [HttpPost]
  168. public void ModifyWorkshopLocation(ChangeContactInfoDTO model)
  169. {
  170. ceoBusiness.ModifyWorkshopLocation(authenticationController.GetUsername(), model.Address, model.CountyID, model.Phone, model.PostalCode);
  171. }
  172. [Authorize]
  173. [HttpGet]
  174. public object GetWorkshopInfo()
  175. {
  176. return ceoBusiness.GetWorkshopInfo(authenticationController.GetUsername());
  177. }
  178. [Authorize]
  179. [HttpGet]
  180. public object GetWorkshopLocationInfo()
  181. {
  182. return ceoBusiness.GetWorkshopLocationInfo(authenticationController.GetUsername());
  183. }
  184. [Authorize]
  185. [HttpGet]
  186. public object FindExperts(string filter = null)
  187. {
  188. return ceoBusiness.FindExperts(authenticationController.GetUsername(), filter);
  189. }
  190. [Authorize]
  191. [HttpPost]
  192. public void HireAnExpert(HireAnExpertDTO model)
  193. {
  194. ceoBusiness.HireAnExpert(authenticationController.GetUsername(), model.ExpertUsername);
  195. }
  196. [Authorize]
  197. [HttpGet]
  198. public object CheckProfileProgress()
  199. {
  200. return ceoBusiness.CheckProfileProgress(authenticationController.GetUsername());
  201. }
  202. }
  203. }