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 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 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(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);
        }