public bool RegsterCustomer(Customer _customer, User _user) { using (var _context = new AskUsDbContext()) { _context.Customers.Add(_customer); _context.SaveChanges(); _user.CustomerId = _customer.Id; _context.Users.Add(_user); _context.SaveChanges(); return(true); } }
/// <summary> /// Function to generate unique token with expiry against the provided userId. /// Also add a record in database for generated token. /// </summary> /// <param name="userId"></param> /// <returns></returns> public Token GenerateToken(int userId) { using (var _context = new AskUsDbContext()) { string token = Guid.NewGuid().ToString(); DateTime issuedOn = DateTime.Now; DateTime expiredOn = DateTime.Now.AddSeconds(3000);//(Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"])); var tokendomain = new Token { UserId = userId, AuthToken = token, IssuedOn = issuedOn, ExpiresOn = expiredOn }; List <Token> tokens = _context.Tokens.Where(x => x.UserId == userId).ToList(); foreach (Token t in tokens) { _context.Tokens.Remove(t); } _context.Tokens.Add(tokendomain); _context.SaveChanges(); return(tokendomain); } }
public void UpdateQuestion(Question question) { using (var _context = new AskUsDbContext()) { _context.Entry(question).State = EntityState.Modified; _context.SaveChanges(); } }
public void AddQuestion(Question question) { using (var _context = new AskUsDbContext()) { _context.Questions.Add(question); _context.SaveChanges(); } }
public void AddUsers(User user) { using (var _context = new AskUsDbContext()) { _context.Users.Add(user); _context.SaveChanges(); } }
public void AddServiceLocation(ServiceLocation serviceLocation) { using (var _context = new AskUsDbContext()) { _context.ServiceLocations.Add(serviceLocation); _context.SaveChanges(); } }
public void UpdateAnswerReview(AnswerReview answerReview) { using (var _context = new AskUsDbContext()) { _context.Entry(answerReview).State = EntityState.Modified; _context.SaveChanges(); } }
public void AddQuestionAnswer(QuestionAnswer questoinAnswer) { using (var _context = new AskUsDbContext()) { _context.QuestionAnswers.Add(questoinAnswer); _context.SaveChanges(); } }
public void DeleteQuestoinsCategory(QuestionsCategory category) { using (var _context = new AskUsDbContext()) { _context.QuestionsCategories.Remove(category); _context.SaveChanges(); } }
public void AddAnswerReview(AnswerReview answerReview) { using (var _context = new AskUsDbContext()) { _context.AnswerReviews.Add(answerReview); _context.SaveChanges(); } }
public void AddQuestionCategory(QuestionsCategory category) { using (var _context = new AskUsDbContext()) { _context.QuestionsCategories.Add(category); _context.SaveChanges(); } }
public void UpdateQuestionsCategory(QuestionsCategory category) { using (var _context = new AskUsDbContext()) { _context.Entry(category).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } }
public void UpdateUserRole(UserRole userRole) { using (var _context = new AskUsDbContext()) { _context.Entry(userRole).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } }
public void AddUserRole(UserRole role) { using (var _context = new AskUsDbContext()) { UserRole userRole = _context.UserRoles.Add(role); _context.SaveChanges(); } }
public void UpdateServiceLocation(ServiceLocation serviceLocation) { using (var _context = new AskUsDbContext()) { _context.Entry(serviceLocation).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } }
public void UpdateQuestionAnswer(QuestionAnswer questionAnswer) { using (var _context = new AskUsDbContext()) { _context.Entry(questionAnswer).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } }
/// <summary> /// Method to validate token against expiry and existence in database. /// </summary> /// <param name="tokenId"></param> /// <returns></returns> public bool ValidateToken(string tokenId) { using (var _context = new AskUsDbContext()) { var token = _context.Tokens.Where(t => t.AuthToken == tokenId && t.ExpiresOn > DateTime.Now).FirstOrDefault(); if (token != null && !(DateTime.Now > token.ExpiresOn)) { token.ExpiresOn = token.ExpiresOn.AddSeconds(3000);//(Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"])); _context.Entry(token).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); return(true); } return(false); } }