public Message ChangeTestStatus(int testId, bool status) { Message message = null; var affectedRow = 0; try { using (TransactionScope scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); if (testId > 0) { var test = _iTestRepository.GetById(testId); test.IsPublished = status; affectedRow = _iTestRepository.Update(test); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been updated successfully.") : SetMessage.SetInformationMessage("No data has been updated."); } scope.Complete(); } } catch (Exception exception) { throw new Exception(exception.Message); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public virtual Message Delete(T entity) { Message message; try { _dbContext.SqlConnection.Open(); var affectedRow = 0; affectedRow = _iBaseRepository.Delete(entity); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been deleted successfully.") : SetMessage.SetInformationMessage("No data has been deleted."); } catch (Exception exception) { message = exception.Message.Substring(0, 50) == "The DELETE statement conflicted with the REFERENCE" ? SetMessage.SetInformationMessage("You can't delete this information because it is already used by other.") : SetMessage.SetErrorMessage(exception.Message); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public virtual Message InsertOrUpdateWithoutIdentity(T entity) { Message message; try { _dbContext.SqlConnection.Open(); var isExist = _iBaseRepository.Get(entity); var affectedRow = 0; if (isExist == null) { affectedRow = _iBaseRepository.InsertWithoutIdentity(entity); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been saved successfully.") : SetMessage.SetInformationMessage("No data has been saved."); } else { affectedRow = _iBaseRepository.Update(entity); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been updated successfully.") : SetMessage.SetInformationMessage("No data has been updated."); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message ChangePassword(User user) { Message message; try { using (var scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); var isExist = _iUserRepository.Get(new User { UserId = user.UserId }); var affectedRow = 0; if (isExist == null) { return(SetMessage.SetInformationMessage("User information not found.")); } var currentPassword = CryptographyHelper.Decrypt(isExist.Password); if (currentPassword != user.CurrentPassword) { return(SetMessage.SetInformationMessage("Invalid current password.")); } isExist.Password = CryptographyHelper.Decrypt(user.Password); affectedRow = _iUserRepository.Update(isExist); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been updated successfully.") : SetMessage.SetInformationMessage("No data has been updated."); message = SetMessage.SetSuccessMessage("Information has been updated successfully."); scope.Complete(); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message AddToFavorite(FavoriteTest favoriteTest) { Message message; try { using (var scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); var affectedRow = 0; var isExist = _iFavoriteTestRepository.GetByUserId(favoriteTest.TestId, favoriteTest.UserId); if (isExist != null) { affectedRow = _iFavoriteTestRepository.Delete(isExist); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Favorite Test remove successfully.") : SetMessage.SetInformationMessage("No data has been deleted."); message.State = 1;// To trace that favorite test is deleted. } else { affectedRow = _iFavoriteTestRepository.InsertWithoutIdentity(favoriteTest); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Test has been favorite successfully.") : SetMessage.SetInformationMessage("No data has been saved."); } scope.Complete(); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message UpdateUserLogoutTime(int userId) { Message message; try { _dbContext.SqlConnection.Open(); var affectedRow = _iUserLoginInformationRepository.UpdateUserLogoutTime(userId); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been saved successfully.") : SetMessage.SetInformationMessage("No data has been saved."); } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message FinishTest(TestTaken testTaken) { Message message; try { using (var scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); if (testTaken.TakenId == 0) { return(SetMessage.SetErrorMessage("Taken Information not found. System unable to process your test result without taken id.")); } var isExist = _iTestTakenRepository.Get(testTaken); var affectedRow = 0; isExist.EndTime = DateTime.UtcNow; var testInformation = _iTestRepository.Get(new Test { TestId = testTaken.TestId }); var correctAnswer = 0; foreach (var details in testTaken.TestTakenDetails) { details.TakenId = isExist.TakenId; details.TestId = isExist.TestId; var correctAnswerOption = String.Join(",", _iQuestionAnswerOptionRepository.GetByQuestionId(details.QuestionId, true).Where(c => c.IsCorrectAnswer).Select(a => a.AnswerOptionId)); var givenAnswerOption = String.Join(",", testTaken.TestTakenDetails.Where(c => c.QuestionId == details.QuestionId).Select(a => a.AnswerOptionId)); if (correctAnswerOption == givenAnswerOption) { details.IsCorrectAnswer = true; correctAnswer++; } _iTestTakenDetailsRepository.InsertWithoutIdentity(details); } var totalQuestion = testInformation.NoOfQuestion; var score = Convert.ToDecimal((correctAnswer * 100.0 / totalQuestion)); isExist.Score = score; affectedRow = _iTestTakenRepository.Update(isExist); var user = _iUserRepository.Get(new User { UserId = isExist.UserId }); //if (user != null && user.RaasForceUserId != null && user.RaasForceUserId > 0) //{ // var restClient = new RestClient(ConfigurationManager.AppSettings["ApiUrl"]); // var request = new RestRequest("api/iTestApp/InsertOrUpdateTestResult?param1=" + user.RaasForceUserId + "¶m2=" + testTaken.TestId + "¶m3=" + testTaken.TakenId + "¶m4=" + score.ToString("#"), Method.GET) { RequestFormat = DataFormat.Json }; // var result = restClient.Execute<HttpResponseMessage>(request); //} message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been saved successfully.") : SetMessage.SetInformationMessage("No data has been saved."); scope.Complete(); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message UpdateUserInformation(User user, HttpPostedFileBase httpPostedFileBase, bool updateImageOnly = false) { Message message; try { using (var scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); var isExist = _iUserRepository.Get(new User { UserId = user.UserId }); var affectedRow = 0; Guid guid; guid = Guid.NewGuid(); HttpPostedFileBase file = httpPostedFileBase; var target = new MemoryStream(); var documentInformatio = new DocumentInformation(); if (isExist == null) { return(SetMessage.SetInformationMessage("User information not found.")); } if (!updateImageOnly) { isExist.FirstName = user.FirstName; isExist.LastName = user.LastName; isExist.MobileNo = user.MobileNo; affectedRow = _iUserRepository.Update(isExist); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been updated successfully.") : SetMessage.SetInformationMessage("No data has been updated."); } if (httpPostedFileBase != null) { file.InputStream.CopyTo(target); } byte[] byteData = target.ToArray(); var imageUtility = new ImageUtility(); #region Insert Document Information if (httpPostedFileBase != null) { var size = imageUtility.GetPreferredImageSize(ImageDimensions.Common); byte[] byteAfterResize = imageUtility.EnforceResize(size.Width, size.Height, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName)); documentInformatio.DocumentName = guid + Path.GetExtension(httpPostedFileBase.FileName); documentInformatio.DocumentByte = byteAfterResize; documentInformatio.DocumentSize = byteAfterResize.Length; _iDocumentInformationRepository.InsertWithoutIdentity(documentInformatio); if (documentInformatio.GlobalId > 0) { if (updateImageOnly) { isExist.PhotoFileName = (guid + Path.GetExtension(httpPostedFileBase.FileName)); isExist.GlobalId = documentInformatio.GlobalId > 0 ? documentInformatio.GlobalId : 0; affectedRow = _iUserRepository.Update(isExist); } else { user.PhotoFileName = (guid + Path.GetExtension(httpPostedFileBase.FileName)); user.GlobalId = documentInformatio.GlobalId > 0 ? documentInformatio.GlobalId : 0; affectedRow = _iUserRepository.Update(user); } } string folderPath = HttpContext.Current.Server.MapPath(Constants.ImagePath.ImageFolderPath); bool isUpload = imageUtility.ImageSaveToPath(folderPath, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName), ImageDimensions.Common); } #endregion message = SetMessage.SetSuccessMessage("Information has been updated successfully."); scope.Complete(); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message Register(User user, HttpPostedFileBase httpPostedFileBase) { Message message; try { using (var scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); var isExist = _iUserRepository.GetUser(user.Email); var affectedRow = 0; Guid guid; guid = Guid.NewGuid(); HttpPostedFileBase file = httpPostedFileBase; var target = new MemoryStream(); var documentInformatio = new DocumentInformation(); int loggedInUserId = WebHelper.CurrentSession.Content.LoggedInUser != null ? WebHelper.CurrentSession.Content.LoggedInUser.UserId : 0; if (isExist == null) { //User password encryption user.Password = CryptographyHelper.Encrypt(user.Password); //By default user will be active user.IsActive = true; // Registration time globalId 0 user.GlobalId = 0; if (loggedInUserId > 0) { user.CreatedBy = loggedInUserId; user.UserType = user.UserType; } else { user.UserType = Convert.ToInt32(AppUsers.User); } affectedRow = _iUserRepository.InsertWithoutIdentity(user); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been saved successfully.") : SetMessage.SetInformationMessage("No data has been saved."); } else { user.IsActive = true; user.UserId = isExist.UserId; user.Password = isExist.Password; affectedRow = _iUserRepository.Update(user); message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been updated successfully.") : SetMessage.SetInformationMessage("No data has been updated."); } if (httpPostedFileBase != null) { file.InputStream.CopyTo(target); } byte[] byteData = target.ToArray(); var imageUtility = new ImageUtility(); #region Insert Document Information if (httpPostedFileBase != null) { var size = imageUtility.GetPreferredImageSize(ImageDimensions.Common); byte[] byteAfterResize = imageUtility.EnforceResize(size.Width, size.Height, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName)); documentInformatio.DocumentName = guid + Path.GetExtension(httpPostedFileBase.FileName); documentInformatio.DocumentByte = byteAfterResize; documentInformatio.DocumentSize = byteAfterResize.Length; _iDocumentInformationRepository.InsertWithoutIdentity(documentInformatio); if (documentInformatio.GlobalId > 0) { user.PhotoFileName = (httpPostedFileBase != null ? guid + Path.GetExtension(httpPostedFileBase.FileName) : null); user.GlobalId = documentInformatio.GlobalId > 0 ? documentInformatio.GlobalId : 0; affectedRow = _iUserRepository.Update(user); } } #endregion #region Image Resize and Save To Path string folderPath = HttpContext.Current.Server.MapPath(Constants.ImagePath.ImageFolderPath); if (httpPostedFileBase != null) { bool isUpload = imageUtility.ImageSaveToPath(folderPath, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName), ImageDimensions.Common); } #endregion scope.Complete(); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message InsertOrUpdateWithoutIdentity(Test test, HttpPostedFileBase httpPostedFileBase) { Message message; try { using (var scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); if (test.NoOfQuestion != test.TestWiseQuestions.Count()) { return(SetMessage.SetErrorMessage("No of question not match! Please select (" + test.NoOfQuestion + ")question from question list")); } var isExist = _iTestRepository.Get(test); var affectedRow = 0; var guid = Guid.NewGuid(); var file = httpPostedFileBase; var target = new MemoryStream(); var documentInformatio = new DocumentInformation(); if (isExist == null) { test.IsActive = true; affectedRow = _iTestRepository.InsertWithoutIdentity(test); foreach (var testWiseQuestions in test.TestWiseQuestions) { testWiseQuestions.TestId = test.TestId; _iTestWiseQuestionRepository.InsertWithoutIdentity(testWiseQuestions); } message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been saved successfully.") : SetMessage.SetInformationMessage("No data has been saved."); } else { affectedRow = _iTestRepository.Update(test); _iTestWiseQuestionRepository.DeleteByTestId(test.TestId); foreach (var testWiseQuestions in test.TestWiseQuestions) { testWiseQuestions.TestId = test.TestId; _iTestWiseQuestionRepository.InsertWithoutIdentity(testWiseQuestions); } message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been updated successfully.") : SetMessage.SetInformationMessage("No data has been updated."); } if (httpPostedFileBase != null) { file.InputStream.CopyTo(target); } byte[] byteData = target.ToArray(); var imageUtility = new ImageUtility(); #region Insert Document Information if (httpPostedFileBase != null) { var size = imageUtility.GetPreferredImageSize(ImageDimensions.Common); byte[] byteAfterResize = imageUtility.EnforceResize(size.Width, size.Height, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName)); documentInformatio.DocumentName = guid + Path.GetExtension(httpPostedFileBase.FileName); documentInformatio.DocumentByte = byteAfterResize; documentInformatio.DocumentSize = byteAfterResize.Length; _iDocumentInformationRepository.InsertWithoutIdentity(documentInformatio); if (documentInformatio.GlobalId > 0) { test.TestIconName = (httpPostedFileBase != null ? guid + Path.GetExtension(httpPostedFileBase.FileName) : null); test.GlobalId = documentInformatio.GlobalId > 0 ? documentInformatio.GlobalId : 0; affectedRow = _iTestRepository.Update(test); } } #endregion #region Image Resize and Save To Path string folderPath = HttpContext.Current.Server.MapPath(Constants.ImagePath.ImageFolderPath); if (httpPostedFileBase != null) { bool isUpload = imageUtility.ImageSaveToPath(folderPath, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName), ImageDimensions.Common); } #endregion scope.Complete(); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }
public Message InsertOrUpdateWithoutIdentity(Question question, HttpPostedFileBase httpPostedFileBase) { Message message; try { using (var scope = new TransactionScope()) { _dbContext.SqlConnection.Open(); var isExistQuestion = _iQuestionRepository.Get(question); var affectedRow = 0; var guid = Guid.NewGuid(); if (isExistQuestion == null) { affectedRow = _iQuestionRepository.InsertWithoutIdentity(question); #region Question Answer Option - Insert foreach (var answerOption in question.QuestionAnswerOptionList) { answerOption.QuestionId = question.QuestionId; _iQuestionAnswerOptionRepository.InsertWithoutIdentity(answerOption); } #endregion message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been saved successfully.") : SetMessage.SetInformationMessage("No data has been saved."); } else { affectedRow = _iQuestionRepository.Update(question); #region Question Answer Option - Update foreach (var answerOption in question.QuestionAnswerOptionList) { answerOption.QuestionId = question.QuestionId; _iQuestionAnswerOptionRepository.Update(answerOption); } #endregion message = affectedRow > 0 ? SetMessage.SetSuccessMessage("Information has been updated successfully.") : SetMessage.SetInformationMessage("No data has been updated."); } #region Question Answer Image if (httpPostedFileBase != null) { var file = httpPostedFileBase; var target = new MemoryStream(); var documentInformatio = new DocumentInformation(); file.InputStream.CopyTo(target); byte[] byteData = target.ToArray(); ImageUtility imageUtility = new ImageUtility(); if (isExistQuestion == null) { #region Insert Document Information var size = imageUtility.GetPreferredImageSize(ImageDimensions.Common); byte[] byteAfterResize = imageUtility.EnforceResize(size.Width, size.Height, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName)); documentInformatio.DocumentName = guid + Path.GetExtension(httpPostedFileBase.FileName); documentInformatio.DocumentByte = byteAfterResize; documentInformatio.DocumentSize = byteAfterResize.Length; _iDocumentInformationRepository.InsertWithoutIdentity(documentInformatio); #region Question - GlobalId Update question.QuestionImageName = (httpPostedFileBase != null ? guid + Path.GetExtension(httpPostedFileBase.FileName) : null); question.GlobalId = documentInformatio.GlobalId > 0 ? documentInformatio.GlobalId : 0; affectedRow = _iQuestionRepository.Update(question); #endregion #endregion } else { #region Update Document Information var isExistDocumentInformatio = _iDocumentInformationRepository.Get(new DocumentInformation { GlobalId = isExistQuestion.GlobalId }); if (isExistDocumentInformatio != null) { var size = imageUtility.GetPreferredImageSize(ImageDimensions.Common); byte[] byteAfterResize = imageUtility.EnforceResize(size.Width, size.Height, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName)); isExistDocumentInformatio.DocumentName = guid + Path.GetExtension(httpPostedFileBase.FileName); isExistDocumentInformatio.DocumentByte = byteAfterResize; isExistDocumentInformatio.DocumentSize = byteAfterResize.Length; _iDocumentInformationRepository.Update(isExistDocumentInformatio); } #endregion } #region Image Resize and Save To Path string folderPath = HttpContext.Current.Server.MapPath(Constants.ImagePath.ImageFolderPath); if (httpPostedFileBase != null) { bool isUpload = imageUtility.ImageSaveToPath(folderPath, byteData, guid + Path.GetExtension(httpPostedFileBase.FileName), ImageDimensions.Common); } #endregion } #endregion scope.Complete(); } } catch (Exception exception) { return(SetMessage.SetErrorMessage(exception.Message)); } finally { _dbContext.SqlConnection.Close(); } return(message); }