public HttpResponseMessage Create(Bizdoc.Data.ViewModels.CreateUserModel model) { //Check that email is not in use if (repo.GetByEmail(model.Email)!=null) { ModelState.AddModelError("Email", "Email address already in use"); } //Check password length if (model.Password.Length<6) { ModelState.AddModelError("Password", "Password must be at least 6 characters"); } if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } User user = UserManager.createUser(model.Email, model.Password); UserTicket ticket = new UserTicket(user); new UserTicketRepository().Create(ticket); var response = Request.CreateResponse<UserTicket>(HttpStatusCode.Created, ticket); return response; }
//private static void printPDF(Bizdoc.Data.Models.PDF pdf) //{ // createPDFFromHTML(pdf.content, pdf.name); //} private static void printPDF(Bizdoc.Data.Models.PDF pdf) { string nameWithExtension = pdf.name + ".pdf"; PDFWriter writer = new PDFWriter(); if (writer.write(pdf.document)) { writer.saveDocument(Path.Combine("C:/PDFDocuments/", nameWithExtension)); } }
public static Models.PDF getPDF(Bizdoc.Data.Models.Document document) { Models.PDF pdf; //Implementation with equals pdf = document.pdfs.Where(o => document.Equals(DocumentManager.getFromRevision((int)document.id, o.documentRevisionId))).FirstOrDefault(); if (pdf==null) { pdf = createPDFFromDocument(document); } return pdf; }
private static Models.PDF createPDFFromDocument(Bizdoc.Data.Models.Document document) { Models.PDF pdf = new Models.PDF(); pdf.document = document; pdf.content = DocumentManager.GetPrint(pdf.document); pdf.documentRevisionId = DocumentManager.getCurrentRevision(pdf.document); pdf.creation = DateTime.Now; pdf.name = pdf.document.id.ToString() + "_" + ((DateTime)pdf.creation).ToString("yyyy-M-dd--HH-mm-ss"); new PDFRepository().Create(pdf); printPDF(pdf); return pdf; }
public ActionResult RedigerNytDatafelt(Bizdoc.Web.ViewModels.NewDataField model) { DataField datafield = new DataField { description = model.description, section = new Section { id = model.sectionId } }; return PartialView(datafield); }
public HttpResponseMessage Invite(Bizdoc.Data.ViewModels.InviteUserModel model) { if (model.companyId==0) { ModelState.AddModelError("companyId", "companyId must be a valid number"); } if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } //Get the current user who is inviting var header = ControllerContext.Request.Headers.SingleOrDefault(x => x.Key == "ApiTicket"); UserTicket ticket = TicketManager.getTicket(header.Value.First()); //get the company that the user is invited to Company company = new CompanyRepository().GetById(model.companyId); //Check if user is allowed to invite if (!ticket.user.affiliations.Any(o => o.company.id==company.id && (o.role.name.Equals("Ejer") || o.role.name.Equals("Admin")))) { return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "User is not allowed to invite users to company " + company.name); } if (model.role.name==null) { model.role = new RoleRepository().GetById(model.role.id); } if (model.role.name.Equals("Ejer")) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Only one user can be owner"); } if (model.role.name.Equals("Admin")) { if (!ticket.user.affiliations.Any(o => o.company.id == company.id && o.role.name.Equals("Ejer"))) { return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Only owners can grant admin"); } } //Get user or create new User user = new UserRepository().GetByEmail(model.email); if (user==null) { user = UserManager.createUserFromInvite(model.email, false); } //Get role and check if valid role name Role role = new RoleRepository().GetByName(model.role.name); if (role==null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid role name"); } if (user.affiliations.Any(x => x.company.id==company.id)) { return Request.CreateErrorResponse(HttpStatusCode.Conflict, "Affiliation already exists"); } UserAffiliation newAffiliation = AffiliationManager.inviteUser(user, company, role, ticket.user); return Request.CreateResponse(HttpStatusCode.Created, newAffiliation); }
public HttpResponseMessage Login(Bizdoc.Data.ViewModels.LoginModel model) { int errorCode = 0; User u = repo.GetByEmail(model.Email); if (u==null) { errorCode = 2; //ModelState.AddModelError("Email", "Wrong email"); } else { if (!u.passwordMatches(model.Password)) { errorCode = 1; //ModelState.AddModelError("Password", "Wrong password"); } //else //{ // if (u.emails.Where(o => o.email == model.Email).First().denied) // { // ModelState.AddModelError("Email", "The email address has been denied use by the owner"); // } // else // { // if (!u.emails.Where(o => o.email == model.Email).First().verified) // { // ModelState.AddModelError("Email", "The email address has not been verified by the user"); // } // } //} } if (errorCode!=0) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorCode.ToString()); } UserTicket ticket = new UserTicket(u); new UserTicketRepository().Create(ticket); var response = Request.CreateResponse<UserTicket>(HttpStatusCode.Created, ticket); return response; }
public ActionResult Login(Bizdoc.Data.ViewModels.LoginModel model) { try { if (ModelState.IsValid) { var response = HttpClientFactory.Client.PostAsJsonAsync("user/login/", model).Result; if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var ticket = response.Content.ReadAsAsync<UserTicket>().Result; LoginHelper.setCookie(this.ControllerContext, ticket); return RedirectToAction("Forside", "Hjem"); } else { System.Web.Http.HttpError error = response.Content.ReadAsAsync<System.Web.Http.HttpError>().Result; int errNum; if (int.TryParse(error.Where(o => o.Key == "Message").First().Value.ToString(), out errNum)) { ViewBag.error = APIErrorCode.getErrorCode(errNum).descDAN; } return View(model); } } else { var allErrors = ModelState.Values.SelectMany(v => v.Errors); ViewBag.error = allErrors.First().ErrorMessage; return View(model); } } catch (Exception e) { throw new Exception("Could not create user", e); } }
public ActionResult Opret(Bizdoc.Data.ViewModels.CreateUserModel model) { try { if (ModelState.IsValid) { var response = HttpClientFactory.Client.PostAsJsonAsync("user/create/", model).Result; if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var ticket = response.Content.ReadAsAsync<UserTicket>().Result; LoginHelper.setCookie(this.ControllerContext, ticket); return RedirectToAction("Forside", "Hjem"); } else { return View(model); } } else { return View(model); } } catch (Exception e) { throw new Exception("Could not create user", e); } }
public ActionResult InviterBruger(Bizdoc.Data.ViewModels.InviteUserModel model) { try { if (ModelState.IsValid) { var response = HttpClientFactory.getClient(this.ControllerContext).PostAsJsonAsync("user/invite/", model).Result; if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var affiliation = response.Content.ReadAsAsync<UserAffiliation>().Result; return Json(new { validModelstate = true }); } else { return Json(new { validModelstate = false, statusCode = response.StatusCode, obj = model }); } } else { return PartialView(model); } } catch (Exception e) { throw new Exception("Could not invite user", e); } }
public bool write(Bizdoc.Data.Models.Document bDoc) { document.Info.Title = bDoc.title; defineStyles(); defineFooter(); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(DocumentManager.GetPrint(bDoc)); foreach (HtmlNode node in htmlDoc.DocumentNode.Descendants()) { Paragraph p; if (node.Name.Equals("h1")) { p = document.LastSection.AddParagraph(node.InnerText, "Heading1"); } else if (node.Name.Equals("h2")) { p = document.LastSection.AddParagraph(node.InnerText, "Heading2"); } else if (node.Name.Equals("p")) { p = document.LastSection.AddParagraph(); string innerHtml = node.InnerHtml; string[] sList = innerHtml.Split(new[] { "<br />", "<br>" }, StringSplitOptions.None); for (int i = 0; i < sList.Length; i++) { HtmlNode innerNode = HtmlNode.CreateNode("<div>" + sList[i] + "</div>"); foreach (HtmlNode n in innerNode.Descendants()) { if (n.NodeType==HtmlNodeType.Element) { if (n.Name.Equals("strong")) { p.AddFormattedText(n.InnerText, TextFormat.Bold); n.InnerHtml = ""; } else if (n.Name.Equals("em")) { p.AddFormattedText(n.InnerText, TextFormat.Italic); n.InnerHtml = ""; } } else if (n.NodeType==HtmlNodeType.Text) { p.AddFormattedText(n.InnerText, "Normal"); } } if (i < sList.Length - 1) { p.AddLineBreak(); } } } } //if (bDoc.title != null && !bDoc.title.Equals("")) //{ // document.LastSection.AddParagraph(bDoc.title, "Heading1"); //} //if (bDoc.sections!=null) //{ // foreach (Bizdoc.Data.Models.Section s in bDoc.sections) // { // writeSection(s); // } //} return true; }
private void writeSection(Bizdoc.Data.Models.Section bSec) { document.LastSection.AddParagraph(bSec.documentIndex + "." + bSec.headline, "Heading2"); if (bSec.htmlContent!=null && !bSec.htmlContent.Equals("")) { writeFromHtml(bSec.renderHtml()); } }