public ActionResult OpretModtager(NewSignature recipient) { //HttpResponseMessage response = HttpClientFactory.getClient(this.ControllerContext).PostAsync("signature/create/", recipient, HttpClientFactory.getFormatter()).Result; HttpResponseMessage response = HttpClientFactory.getClient(this.ControllerContext).PostAsJsonAsync("signature/create/", recipient).Result; if (response.IsSuccessStatusCode) { return Json(new { validModelstate = true }); } else { return Json(new { validModelstate = false, statusCode = response.StatusCode, statusMessage = response.Content.ReadAsStringAsync().Result }); } }
public HttpResponseMessage Create(NewSignature signature) { //General stuff if (signature==null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Signature cannot be null"); } if (signature.recipientEmail==null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Email cannot be null"); } //Get user or create new User user = new UserRepository().GetByEmail(signature.recipientEmail); if (user == null) { user = UserManager.createUserFromInvite(signature.recipientEmail, true); } //Retrieve PDF PDF pdf = new PDFRepository().GetById(signature.pdfId); if (pdf==null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "PDF id is not valid"); } //Check access rights for current user UserTicket ticket = TicketManager.getTicketFromContext(this.ControllerContext); if (!pdf.document.ownerCompany.userAffiliations.Any(x => x.user.id==ticket.user.id && (x.role.name.Equals("Ejer")||x.role.name.Equals("Admin")))) { return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User permission is not sufficient"); } if (!signature.type.Equals("private") && !signature.type.Equals("business")) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Type must be either \"business\" or \"private\""); } Signature newSignature; if (signature.type.Equals("business")) { BusinessSignature tempSignature = new BusinessSignature(); if (signature.cvr==null||CompanyManager.validateCVR(signature.cvr)) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid CVR-number"); } Company company = new CompanyRepository().GetByCVR(signature.cvr); if (company==null) { company = CompanyManager.createCompany(signature.cvr, user); } //logic to determine whether user is affiliated with company and if not, decide how to affiliate him/her. Request to admin/owner? //add later tempSignature.company = company; newSignature = tempSignature; } else //== type equals private { PrivateSignature tempSignature = new PrivateSignature(); if (signature.cpr!=null) { if (signature.cpr.Length==10) { tempSignature.cpr = signature.cpr; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid CPR-number"); } } else { if (signature.secure||signature.isSignature) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "CPR-number is needed for signature"); } } newSignature = tempSignature; } newSignature.creation = DateTime.Now; newSignature.user = user; newSignature.pdf = pdf; newSignature.secure = signature.secure; newSignature.isSignature = signature.isSignature; newSignature.message = signature.message; newSignature.sender = ticket.user; new SignatureRepository().Create(newSignature); return Request.CreateResponse<Signature>(HttpStatusCode.OK, newSignature); }