public HttpResponseMessage CreateUser([FromBody] User value) { try { using (var context = new ToPDFDBContext()) { var user = new User(); user.AddressLine1 = value.AddressLine1; user.AddressLine2 = value.AddressLine2; user.City = value.City; user.CompanyName = value.CompanyName; user.CompanyWebsite = value.CompanyWebsite; user.Country = value.Country; user.Email = value.Email; user.FirstName = value.FirstName; user.LastName = value.LastName; user.Password = value.Password; user.Phone = value.Phone; user.PostCode = value.PostCode; user.State = value.State; user.Avatar = value.Avatar; user.CreatedDate = DateTime.Now; context.Users.Add(user); context.SaveChanges(); return(SendHttpResponse("Success", HttpStatusCode.OK)); } } catch (Exception ex) { return(SendHttpResponse(ex.Message, HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage Subscriptions() { try { using (var context = new ToPDFDBContext()) { var val = context.Subscriptions.Select(c => new { SubscriptionName = c.SubscriptionName, Price = c.Price }).ToList(); return(SendHttpResponse(val, HttpStatusCode.OK)); } } catch (Exception e) { return(SendHttpResponse(e.Message, HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage EmailExists(string email) { try { using (var context = new ToPDFDBContext()) { bool val = context.Users.Any(c => c.Email == email); return(SendHttpResponse(val, HttpStatusCode.OK)); } } catch (Exception e) { return(SendHttpResponse(e.Message, HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage CreateTemplate([FromBody] Models.PdfTemplate template) { try { using (var context = new ToPDFDBContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var pdfTemplate = new Models.PdfTemplate(); pdfTemplate.ApiKey = GetApiKey(); pdfTemplate.ContactEmail = template.ContactEmail; pdfTemplate.CreatedDate = DateTime.UtcNow; pdfTemplate.DeliveryModeId = template.DeliveryModeId; pdfTemplate.Desc = template.Desc; pdfTemplate.EmailErrorTo = template.EmailErrorTo; pdfTemplate.InputType = template.InputType; pdfTemplate.IsActive = true; pdfTemplate.IsDeleted = false; pdfTemplate.PdfTemplateName = template.PdfTemplateName; pdfTemplate.SampleData = template.SampleData; pdfTemplate.UserId = template.UserId; pdfTemplate.TemplateSections = GetTemplateSections(template.TemplateSections); context.PdfTemplates.Add(pdfTemplate); context.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception) { dbContextTransaction.Rollback(); throw; } } return(SendHttpResponse("Success", HttpStatusCode.OK)); } } catch (Exception e) { return(SendHttpResponse(e.Message, HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage Dashboard(int userId) { try { using (var context = new ToPDFDBContext()) { var user = context.Users.FirstOrDefault(c => c.UserId == userId); if (user != null) { return(SendHttpResponse(GetLoginResult(user), HttpStatusCode.OK)); } } return(SendHttpResponse("User not found", HttpStatusCode.InternalServerError)); } catch (Exception e) { return(SendHttpResponse(e.Message, HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage Login([FromBody] dynamic value) { try { using (var context = new ToPDFDBContext()) { string e = value.Email; string p = value.Password; var user = context.Users.FirstOrDefault(c => c.Email == e && c.Password == p); if (user == null) { return(SendHttpResponse("Not Authenticated", HttpStatusCode.InternalServerError)); } return(SendHttpResponse(user.UserId, HttpStatusCode.OK)); } } catch (Exception e) { return(SendHttpResponse(e.Message, HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage ResetPwdAndEmail(string email) { try { using (var context = new ToPDFDBContext()) { var user = context.Users.FirstOrDefault(c => c.Email == email); if (user != null) { string p = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 8); user.Password = Convert.ToBase64String(Encoding.ASCII.GetBytes(p)); context.SaveChanges(); SendEmail(p, email); } return(SendHttpResponse("Success", HttpStatusCode.OK)); } } catch (Exception e) { return(SendHttpResponse(e.Message, HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage VerifyEmail(string email) { try { using (var context = new ToPDFDBContext()) { var user = context.Users.FirstOrDefault(c => c.Email == email); if (user != null) { user.EmailVerifiedDate = DateTime.Now; context.SaveChanges(); return(SendHttpResponse("Success", HttpStatusCode.OK)); } else { return(SendHttpResponse("Email Not Found", HttpStatusCode.InternalServerError)); } } } catch (Exception e) { return(SendHttpResponse(e.Message, HttpStatusCode.InternalServerError)); } }
private UserAccountDto GetLoginResult(User user) { string token = Encrypt(user.Email + "|" + DateTime.Now.ToString("yyyyMMddHHmmssff")); var r = new UserAccountDto(); r.User = new UserDto() { AuthToken = token, UserId = user.UserId, UserName = user.FirstName + " " + user.LastName, Email = user.Email }; r.SuccessCount = 0; r.ErrorCount = 0; using (var context = new ToPDFDBContext()) { r.Messages = null; r.PdfTemplates = context.PdfTemplates.Where(c => c.UserId == user.UserId && !c.IsDeleted).Take(20).Select (s => new PdfTemplateDto() { ApiKey = s.ApiKey, ContactEmail = s.ContactEmail, CreatedDate = s.CreatedDate, DeliveryMode = s.DeliveryMode.DeliveryModeName, Desc = s.Desc, EmailErrorTo = s.EmailErrorTo, IsActive = s.IsActive, PdfTemplateDesc = s.Desc, PdfTemplateName = s.PdfTemplateName, SuccessRate = 0 }).ToList(); r.Subscription = context.UserSubscriptions.Where(c => c.UserId == user.UserId).Select( c => new SubscriptionDto() { SubscriptionName = c.Subscription.SubscriptionName, SubscriptionEndDate = c.EndDate, SubscriptionStatus = c.Status }).ToList(); } return(r); }