Пример #1
0
 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);
     }
 }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
 public void UpdateQuestion(Question question)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Entry(question).State = EntityState.Modified;
         _context.SaveChanges();
     }
 }
Пример #4
0
 public void AddQuestion(Question question)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Questions.Add(question);
         _context.SaveChanges();
     }
 }
Пример #5
0
 public void AddUsers(User user)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Users.Add(user);
         _context.SaveChanges();
     }
 }
Пример #6
0
 public void AddServiceLocation(ServiceLocation serviceLocation)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.ServiceLocations.Add(serviceLocation);
         _context.SaveChanges();
     }
 }
Пример #7
0
 public void UpdateAnswerReview(AnswerReview answerReview)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Entry(answerReview).State = EntityState.Modified;
         _context.SaveChanges();
     }
 }
Пример #8
0
 public void AddQuestionAnswer(QuestionAnswer questoinAnswer)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.QuestionAnswers.Add(questoinAnswer);
         _context.SaveChanges();
     }
 }
Пример #9
0
 public void DeleteQuestoinsCategory(QuestionsCategory category)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.QuestionsCategories.Remove(category);
         _context.SaveChanges();
     }
 }
Пример #10
0
 public void AddAnswerReview(AnswerReview answerReview)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.AnswerReviews.Add(answerReview);
         _context.SaveChanges();
     }
 }
Пример #11
0
 public void AddQuestionCategory(QuestionsCategory category)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.QuestionsCategories.Add(category);
         _context.SaveChanges();
     }
 }
Пример #12
0
 public void UpdateQuestionsCategory(QuestionsCategory category)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
 }
Пример #13
0
 public void UpdateUserRole(UserRole userRole)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Entry(userRole).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
 }
Пример #14
0
 public void AddUserRole(UserRole role)
 {
     using (var _context = new AskUsDbContext())
     {
         UserRole userRole = _context.UserRoles.Add(role);
         _context.SaveChanges();
     }
 }
Пример #15
0
 public void UpdateServiceLocation(ServiceLocation serviceLocation)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Entry(serviceLocation).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
 }
Пример #16
0
 public void UpdateQuestionAnswer(QuestionAnswer questionAnswer)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Entry(questionAnswer).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
 }
Пример #17
0
 /// <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);
     }
 }