public static OperationStatus CreateFromException(string message, Exception ex)
        {
            OperationStatus opStatus = new OperationStatus
            {
                Status = false,
                Message = message
            };
            if (ex != null)
            {
                opStatus.ExceptionMessage = ex.Message;
                opStatus.ExceptionStackTrace = ex.StackTrace;
                opStatus.ExceptionInnerMessage = ex.InnerException == null ? "" : ex.InnerException.ToString();
                opStatus.InnerExceptionStackTrace = ex.InnerException == null ? "" : ex.InnerException.StackTrace;
            }
            return opStatus;

        }
        public static OperationStatus CreateFromException(string message, DbEntityValidationException ex)
        {
            OperationStatus opStatus = new OperationStatus
            {
                Status = false,
                Message = message
            };
            if (ex != null)
            {
                var validationMsgs = ex.EntityValidationErrors.SelectMany(s => s.ValidationErrors).Select(s => s.ErrorMessage);
                if (validationMsgs != null)
                {
                    var strErrMsgs = string.Join(";", validationMsgs);
                    opStatus.ExceptionMessage = ex.Message;
                    opStatus.ExceptionMessage = String.Format("{0} Validation errors : {1}", opStatus.ExceptionMessage, strErrMsgs);
                    opStatus.ExceptionStackTrace = ex.StackTrace;
                    opStatus.ExceptionInnerMessage = ex.InnerException == null ? "" : ex.InnerException.ToString();
                    opStatus.InnerExceptionStackTrace = ex.InnerException == null ? "" : ex.InnerException.StackTrace;
                }
            }
            return opStatus;

        }
        private int SaveAttachedDocument(CreateIssue model, OperationStatus result, int fileCounter, HttpPostedFileBase file)
        {
            if (file != null)
            {
                fileCounter++;

                string fileName = Path.GetFileName(file.FileName).ToLower();
                string fileKey = fileName;
                fileKey = fileKey.Replace(" ", "-").Replace("%", "-");

                fileKey = String.Format("{0}-{1}-{2:n}-{3}", result.OperationID, fileCounter, Guid.NewGuid(), fileName);

                if (fileKey.Length > 99)
                    fileKey = fileKey.Substring(0, 99);

                string path = Path.Combine(Server.MapPath("~/uploads"), fileKey);
                file.SaveAs(path);

                Document img = new Document { FileName = fileName, ParentID = model.Id };
                img.FileAlias = fileKey;
                img.CreatedByID = UserID;
                img.ParentID = result.OperationID;
                var resultForImg = repo.SaveDocument(img);
                if (!resultForImg.Status)
                    log.Debug(resultForImg);
            }
            return fileCounter;
        }
        public OperationStatus SaveUser(User user)
        {
            try
            {
                if (user.ID == 0)
                {
                    user.CreatedDate = DateTime.UtcNow;
                    db.Users.Add(user);
                }
                else
                {
                    db.Entry(user).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                return  OperationStatus.CreateFromException("error", dbEx);
            }
            catch (Exception ex)
            {
                var res = new OperationStatus();

            }
            return new OperationStatus { OperationID = user.ID, Status = true };
        }