public JsonResult SaveMainErrorDetails(ErrorMaster errorObjParam, SolutionMaster solObjParam, ErrorAttachment[] errorImageList,
                                               ErrorAttachment[] solutionImageList, bool isSolutionAddForError, bool isErrorWithSolution)
        {
            FormsAuthenticationTicket ticket = null;

            try
            {
                _UserDetailsBusinessLogic = new UserDetailsBusinessLogic();
                HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                ticket = FormsAuthentication.Decrypt(authCookie.Value);
                int currentUserId = _UserDetailsBusinessLogic.GetUserID(ticket.Name);

                _ErrorMgtBusinesssLogic = new ErrorMgtBusinesssLogic();
                var retVal = string.Empty;

                retVal = _ErrorMgtBusinesssLogic.SaveMainErrorDetails(errorObjParam, solObjParam, errorImageList,
                                                                      solutionImageList, isSolutionAddForError, isErrorWithSolution, currentUserId);

                return(Json(retVal));
            }
            catch (Exception ex)
            {
                currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                methodName = sf.GetMethod().Name;
                ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex);
                return(Json("0000"));
            }
        }
        public string SaveMainErrorDetails(ErrorMaster errorObjParam, SolutionMaster solObjParam, ErrorAttachment[] errorImageList,
                                           ErrorAttachment[] solutionImageList, bool isSolutionAddForError, bool isErrorWithSolution, int userId = 1)
        {
            using (TransactionScope scope1 = new TransactionScope())
            {
                try
                {
                    string formattedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

                    var ErrorCollection    = mongoDatabaseRunTime.GetCollection <ErrorMaster>("ErrorMaster");
                    var SolutionCollection = mongoDatabaseRunTime.GetCollection <SolutionMaster>("SolutionMaster");

                    int newErrorID    = GetNewErrorID();
                    int newSolutionID = GetNewSolutionID();

                    //To Convert Image array to list
                    List <ErrorAttachment> _ErrorImgList = new List <ErrorAttachment>();
                    List <ErrorAttachment> _SolutionImgList = new List <ErrorAttachment>();
                    ErrorAttachment        _ErrorImgFile, _SolutionImageFile;

                    //To store solutions
                    List <SolutionMaster> _SolutionMasterList = new List <SolutionMaster>();

                    //Images for error
                    if (errorImageList != null)
                    {
                        foreach (var imgMedia in errorImageList)
                        {
                            _ErrorImgFile                   = new ErrorAttachment();
                            _ErrorImgFile.MediaType         = imgMedia.MediaType;
                            _ErrorImgFile.MediaName         = imgMedia.MediaName;
                            _ErrorImgFile.IsErrorAttachment = imgMedia.IsErrorAttachment;
                            _ErrorImgFile.MediaURL          = imgMedia.MediaURL;
                            _ErrorImgFile.ClientId          = errorObjParam.ClientId;
                            _ErrorImgFile.ErrorId           = newErrorID;
                            _ErrorImgFile.IsErrorAttachment = imgMedia.IsErrorAttachment;
                            _ErrorImgFile.MediaMIMEType     = imgMedia.MediaMIMEType;
                            _ErrorImgFile.MediaPath         = imgMedia.MediaPath;
                            _ErrorImgList.Add(_ErrorImgFile);
                        }
                    }

                    //Images for solution
                    if (solutionImageList != null)
                    {
                        foreach (var imgMedia in solutionImageList)
                        {
                            _SolutionImageFile                   = new ErrorAttachment();
                            _SolutionImageFile.MediaType         = imgMedia.MediaType;
                            _SolutionImageFile.MediaName         = imgMedia.MediaName;
                            _SolutionImageFile.MediaURL          = imgMedia.MediaURL;
                            _SolutionImageFile.ClientId          = errorObjParam.ClientId;
                            _SolutionImageFile.ErrorId           = newErrorID;
                            _SolutionImageFile.IsErrorAttachment = imgMedia.IsErrorAttachment;
                            _SolutionImageFile.MediaMIMEType     = imgMedia.MediaMIMEType;
                            _SolutionImageFile.MediaPath         = imgMedia.MediaPath;
                            _SolutionImgList.Add(_SolutionImageFile);
                        }
                    }

                    if (isErrorWithSolution == false && isSolutionAddForError == false)
                    {
                        var errorTuple = new ErrorLogDataAccess.DataClasses.ErrorMaster()
                        {
                            ErrorId          = newErrorID,
                            ErrorCode        = errorObjParam.ErrorCode,
                            DomainId         = errorObjParam.DomainId,
                            FieldId          = errorObjParam.FieldId,
                            ClientId         = errorObjParam.ClientId,
                            ErrorCaption     = errorObjParam.ErrorCaption,
                            ErrorDescription = errorObjParam.ErrorDescription,
                            UserId           = userId,//Must get the userID from session later
                            ErrorLogDate     = formattedDate,
                            ErrorAttachments = _ErrorImgList.ToList(),
                        };

                        ErrorCollection.InsertOneAsync(errorTuple);
                    }
                    else if (isErrorWithSolution == true)
                    {
                        var solutionTuple = new ErrorLogDataAccess.DataClasses.SolutionMaster()
                        {
                            SolutionId       = newSolutionID,
                            SolutionCode     = solObjParam.SolutionCode,
                            ErrorId          = newErrorID,
                            DomainId         = solObjParam.DomainId,
                            FieldId          = solObjParam.FieldId,
                            ClientId         = solObjParam.ClientId,
                            UserId           = userId,
                            SolutionComment  = solObjParam.SolutionComment,
                            SolutionLogDate  = formattedDate,
                            ErrorAttachments = _SolutionImgList.ToList()
                        };

                        _SolutionMasterList.Add(solutionTuple);

                        var errorTuple = new ErrorLogDataAccess.DataClasses.ErrorMaster()
                        {
                            ErrorId          = newErrorID,
                            ErrorCode        = errorObjParam.ErrorCode,
                            DomainId         = errorObjParam.DomainId,
                            FieldId          = errorObjParam.FieldId,
                            ClientId         = errorObjParam.ClientId,
                            ErrorCaption     = errorObjParam.ErrorCaption,
                            ErrorDescription = errorObjParam.ErrorDescription,
                            UserId           = 1,//Must get the userID from session later
                            ErrorLogDate     = formattedDate,
                            ErrorAttachments = _ErrorImgList.ToList(),
                            SolutionMasters  = _SolutionMasterList.ToList()
                        };

                        //First add the error
                        ErrorCollection.InsertOne(errorTuple);

                        //Then add the solution
                        SolutionCollection.InsertOne(solutionTuple);
                    }

                    else if (isSolutionAddForError == true)
                    {
                        //Get the specific error tuple/document ID
                        var errorTupleId = ErrorCollection.AsQueryable()
                                           .Where(a => a.ErrorCode == errorObjParam.ErrorCode)
                                           .FirstOrDefault().ErrorId;

                        //Get the existing solutions for this error
                        _SolutionMasterList = SolutionCollection.AsQueryable()
                                              .Where(a => a.ErrorId == errorTupleId).ToList();

                        var solutionTuple = new ErrorLogDataAccess.DataClasses.SolutionMaster()
                        {
                            SolutionId       = newSolutionID,
                            SolutionCode     = solObjParam.SolutionCode,
                            ErrorId          = errorTupleId,
                            DomainId         = solObjParam.DomainId,
                            FieldId          = solObjParam.FieldId,
                            ClientId         = solObjParam.ClientId,
                            UserId           = userId,
                            SolutionComment  = solObjParam.SolutionComment,
                            SolutionLogDate  = formattedDate,
                            ErrorAttachments = _SolutionImgList.ToList()
                        };

                        _SolutionMasterList.Add(solutionTuple);

                        //Add the solution to the document
                        SolutionCollection.InsertOne(solutionTuple);


                        var filterObj = Builders <ErrorLogDataAccess.DataClasses.ErrorMaster> .Filter.Eq("ErrorCode", errorObjParam.ErrorCode);

                        var updateObj = Builders <ErrorLogDataAccess.DataClasses.ErrorMaster> .Update
                                        .Set("LastUpdatedDate", formattedDate)
                                        .Set("SolutionMasters", _SolutionMasterList)
                                        .CurrentDate("lastModified");

                        //Then update the ErrorMaster document with the updated SolutionMaster list
                        ErrorCollection.UpdateOne(filterObj, updateObj);
                    }


                    scope1.Complete();

                    return(errorObjParam.ErrorCode);
                }
                catch (Exception ex)
                {
                    scope1.Dispose();
                    //return "0000";
                    throw;
                }
            }
        }