// To Participate in Course public bool ParticipateInCourse(string Token, long CourseID) { bool isParticipated = false; try { long UserID = Utility.GetUserIDByToken(Token); if (UserID > 0 && CourseID > 0) { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { CourseParticipant dbUserParticipated = new CourseParticipant(); dbUserParticipated.UserID = UserID; dbUserParticipated.CourseID = CourseID; dbUserParticipated.CreatedDate = DateTime.Now; dbUserParticipated.UpdatedDate = DateTime.Now; dbContext.CourseParticipants.Add(dbUserParticipated); dbContext.SaveChanges(); isParticipated = true; } } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(isParticipated); }
// Update Course Detail public bool UpdateCourse(CourseModel _CourseModel) { bool isUpdated = false; try { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { Cours dbCourse = dbContext.Courses.Where(x => x.CourseID == _CourseModel.CourseID).FirstOrDefault(); if (dbCourse != null && dbCourse.CourseID > 0) { dbCourse.CourseName = _CourseModel.CourseName; dbCourse.CourseDescription = _CourseModel.CourseDescription; dbCourse.UpdatedDate = DateTime.Now; dbContext.SaveChanges(); isUpdated = true; } } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(isUpdated); }
public UserModel LoginUser(UserModel model) { UserModel user = new UserModel(); try { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { User dbUser = dbContext.Users.Where(x => x.UserName == model.UserName && x.Password == model.Password).FirstOrDefault(); if (dbUser != null && dbUser.UserID > 0) { user.UserName = dbUser.UserName; user.UserRole = dbUser.UserRole.Role; // Generate Token and save in db with Expiry value double TokenExpiry = Utility.ToDouble(ConfigurationManager.AppSettings["TokenExpiry"].ToString()); if (TokenExpiry == 0) { TokenExpiry = 1; } UserToken dbToken = new UserToken(); dbToken.UserID = dbUser.UserID; dbToken.Token = Guid.NewGuid().ToString(); dbToken.TokenCreatedDate = DateTime.Now; dbToken.TokenExpiryDate = DateTime.Now.AddHours(TokenExpiry); dbToken.CreatedDate = DateTime.Now; dbToken.UpdatedDate = DateTime.Now; dbContext.UserTokens.Add(dbToken); dbContext.SaveChanges(); user.Token = dbToken.Token; } } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(user); }
public bool LogoutUser(string Token) { bool isLoggedOut = false; try { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { UserToken dbUserToken = dbContext.UserTokens.Where(x => x.Token == Token).FirstOrDefault(); if (dbUserToken != null && dbUserToken.UserTokenID > 0) { dbContext.UserTokens.Remove(dbUserToken); dbContext.SaveChanges(); isLoggedOut = true; } } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(isLoggedOut); }
// Add New Course public bool AddCourse(CourseModel _CourseModel) { bool isAdded = false; try { using (ResultatPartnerASEntities dbContext = new ResultatPartnerASEntities()) { Cours dbCourse = new Cours(); dbCourse.CourseName = _CourseModel.CourseName; dbCourse.CourseDescription = _CourseModel.CourseDescription; dbCourse.CreatedDate = DateTime.Now; dbCourse.UpdatedDate = DateTime.Now; dbContext.Courses.Add(dbCourse); dbContext.SaveChanges(); isAdded = true; } } catch (Exception ex) { LogManager.writelog(ex.Message); } return(isAdded); }