public void GetInitialDropDowns(CreateProblemObject createproblemobj)
        {
            ResponseObjectForAnything responseObject = new ResponseObjectForAnything();
            MasterlistEngine masterEngine = new MasterlistEngine();
            string response = masterEngine.GetDropDownItemsJSON(Request.Cookies["sessionkey"].Value);
            responseObject = (ResponseObjectForAnything)Serializer.JSONStringToObject<ResponseObjectForAnything>(response);
            createproblemobj = (CreateProblemObject)Serializer.JSONStringToObject<CreateProblemObject>(responseObject.ResultObjectJSON);
            ViewBag.Country = new SelectList(createproblemobj.countries, "CountryID", "CountryName");
            ViewBag.CompanyID = new SelectList(createproblemobj.companies, "CompanyID", "CompanyName");
            ViewBag.CategoryID = new SelectList(createproblemobj.categories, "ID", "Name");
            ViewBag.ProductStatusID = new SelectList(createproblemobj.productstatuses, "ProductStatusID", "ProductStatusName");
            ViewBag.PinCode = createproblemobj.PinCode;
            //List<DropDownViewModel> categoryList = new List<DropDownViewModel>();
            //categoryList.Add(new DropDownViewModel { Name = "Electronics", ID = 1 });
            //categoryList.Add(new DropDownViewModel { Name = "Furniture", ID = 2 });
            //model.CategoryList = categoryList;
            ////ViewBag.CategoryId = new SelectList(model.CategoryList, "ID", "Name"); ;

            //List<DropDownViewModel> companyList = new List<DropDownViewModel>();
            //companyList.Add(new DropDownViewModel { Name = "Google", ID = 1 });
            //companyList.Add(new DropDownViewModel { Name = "Yahoo", ID = 2 });
            //companyList.Add(new DropDownViewModel { Name = "Facebook", ID = 3 });
            //companyList.Add(new DropDownViewModel { Name = "Microsoft", ID = 4 });
            //companyList.Add(new DropDownViewModel { Name = "Intel", ID = 5 });
            //model.CompanyList = companyList;

            //List<DropDownViewModel> statusList = new List<DropDownViewModel>();
            //statusList.Add(new DropDownViewModel { Name = "In Warranty", ID = 1 });
            //statusList.Add(new DropDownViewModel { Name = "In Guaranty", ID = 2 });
            //model.ProductStatusList = statusList;

            //List<DropDownViewModel> countryList = new List<DropDownViewModel>();
            //countryList.Add(new DropDownViewModel { Name = "India", ID = 1 });
            //countryList.Add(new DropDownViewModel { Name = "Australia", ID = 2 });
            //countryList.Add(new DropDownViewModel { Name = "New Zealand", ID = 3 });
            //countryList.Add(new DropDownViewModel { Name = "Canada", ID = 4 });
            //model.CountryList = countryList;
        }
 /// <summary>
 /// Action for create a new problem
 /// </summary>
 /// <returns></returns>
 public ActionResult CreateProblem()
 {
     ViewBag.ActiveMenu = "LiPostProblems";
     CreateProblemObject createproblemobj = new CreateProblemObject();
     GetInitialDropDowns(createproblemobj);
     return View(createproblemobj);
 }
        public ActionResult CreateProblem(Problem model, FormCollection form)
        {
            var experts = Request.Form["UserSuggestedExperts"];
            var tags = Request.Form["Tag"];
            HttpFileCollectionBase files = Request.Files;
            ProblemEngine probEngine = new ProblemEngine();
            ResponseObjectForAnything responseObject = new ResponseObjectForAnything();
            CreateProblemObject complexmodel = new CreateProblemObject();
            GetInitialDropDowns(complexmodel);
            int count = 0;
            int actualcount = 0;
            int problemid = 0;
            string[] filePaths = new string[Request.Files.Count];
            string[] fileExtns = new string[Request.Files.Count];
            if (form["ResolutionMethod"] == "Yes")
                form["ResolutionMethod"] = "true";
            else
                form["ResolutionMethod"] = "false";
            if (form["RegisteredAddress"] == "Yes")
                form["RegisteredAddress"] = "true";
            else
                form["RegisteredAddress"] = "false";
            string resultmessage = "";
            if (files.Count > 0)
            {
                foreach (string file in Request.Files)
                {
                    HttpPostedFileBase hpf = Request.Files[count] as HttpPostedFileBase;

                    if (hpf.ContentLength > 0)
                    {
                        string newFileName = Guid.NewGuid().ToString() + "_" + hpf.FileName.Replace(" ", "_");
                        string relativePath = @"~\upload\problem-image\" + newFileName;
                        hpf.SaveAs(Server.MapPath(relativePath));
                        filePaths[actualcount] = ConfigurationManager.AppSettings["ApplicationURL"] + ConfigurationManager.AppSettings["problemimage"] + newFileName;
                        if (newFileName.ToLower().Contains("gif") || newFileName.ToLower().Contains("png") || newFileName.ToLower().Contains("jpg") || newFileName.ToLower().Contains("jpeg"))
                            fileExtns[actualcount] = "image";
                        else
                            fileExtns[actualcount] = "video";
                        actualcount++;
                    }
                    count++;
                }
            }
            string response = probEngine.SaveProblemJSON(Request.Cookies["sessionkey"].Value, null, form["CompanyRelated"], form["CompanyID"], form["ProblemHeading"],
                            form["CategoryID"], form["SubCategory"], form["Product"], form["ModelNo"], form["Description"], form["PurchaseMonth"], form["PurchaseYear"],
                            form["ProductStatusID"], form["ResolutionNeededBy"], form["Tag"], form["ResolutionMethod"], form["RegisteredAddress"], form["AddressLine1"],
                            form["AddressLine2"], form["AddressLine3"], form["City"], form["State"], form["Country"], form["Pincode"]);
            if (!string.IsNullOrEmpty(response)) { responseObject = (ResponseObjectForAnything)Serializer.JSONStringToObject<ResponseObjectForAnything>(response); }
            problemid = responseObject.ResultObjectID;
            bool isValid = false;
            if(responseObject.ResultCode == "SUCCESS")
            {
                isValid = true;
                resultmessage = responseObject.ResultMessage;
                for (int fileCt = 0; fileCt < actualcount; fileCt++)
                {
                    if(filePaths[fileCt] != string.Empty)
                    {
                        response = "";
                        if(fileCt == 0)
                            response = probEngine.SaveMedia(Request.Cookies["sessionkey"].Value, responseObject.ResultObjectID.ToString(), filePaths[fileCt], fileExtns[fileCt], true);
                        else
                            response = probEngine.SaveMedia(Request.Cookies["sessionkey"].Value, responseObject.ResultObjectID.ToString(), filePaths[fileCt], fileExtns[fileCt], false);
                    }
                }
                responseObject = (ResponseObjectForAnything)Serializer.JSONStringToObject<ResponseObjectForAnything>(response);

                if(responseObject.ResultCode == "SUCCESS")
                {
                    if(experts.Count() > 0)
                    {
                        response = probEngine.InviteExpertsJSON(Request.Cookies["sessionkey"].Value, problemid.ToString(), experts);
                        responseObject = (ResponseObjectForAnything)Serializer.JSONStringToObject<ResponseObjectForAnything>(response);
                        if(responseObject.ResultCode == "SUCCESS")
                        {
                            isValid = true;
                        }
                    }
                }
                else
                {
                    isValid = false;
                }
            }
            else
            {
                isValid = false;
            }
            if(!isValid)
            {
                Common.DTO.Alert alert = new Common.DTO.Alert();
                alert.AlertType = Common.DTO.Alert.ALERTTYPE.Error;
                alert.Message = responseObject.ResultMessage;
                alert.MessageType = Common.DTO.Alert.ALERTMESSAGETYPE.OnlyText;
                ViewBag.AlertMessageModel = alert;
            }
            else
            {
                Common.DTO.Alert alert = new Common.DTO.Alert();
                alert.AlertType = Common.DTO.Alert.ALERTTYPE.Success;
                alert.Message = responseObject.ResultMessage;
                alert.MessageType = Common.DTO.Alert.ALERTMESSAGETYPE.TextWithClose;
                ViewBag.AlertMessageModel = alert;
            }
            //if (!string.IsNullOrEmpty(model.VideoStremName1))
            //{
            //    string DirectoryName = ServerSettings.VideoStoragePhysicalFolderPath;

            //    int status = Mapping.ConvertToMp4(ServerSettings.MEDIASERVERURL, model.VideoStremName1 + ".flv", DirectoryName, model.VideoStremName1 + ".mp4");

            //}
            //if (!string.IsNullOrEmpty(model.VideoStremName2))
            //{
            //    string DirectoryName = ServerSettings.VideoStoragePhysicalFolderPath;

            //    int status = Mapping.ConvertToMp4(ServerSettings.MEDIASERVERURL, model.VideoStremName2 + ".flv", DirectoryName, model.VideoStremName2 + ".mp4");

            //}
            return View(complexmodel);
        }
        /// <summary>
        /// Get master list of dropdowns for create problem page.
        /// </summary>
        /// <param name="sessionkey">string</param>
        /// <returns>string</returns>
        public ResponseObjectForAnything GetDropDownItems(string sessionkey)
        {
            List<Company> lstcompany = new List<Company>();
            List<Category> lstcategory = new List<Category>();
            List<Country> lstcountry = new List<Country>();
            List<ProductStatus> lstproductstatus = new List<ProductStatus>();
            List<ResolutionMethod> lstresolutionmethod = new List<ResolutionMethod>();
            CreateProblemObject createproblemobj = new CreateProblemObject();
            AuthenticationEngine authEngine = new AuthenticationEngine();
            bool isValid = authEngine.IsValidSession(sessionkey);
            int count = 0;
            ResponseObjectForAnything responseObject = new ResponseObjectForAnything();

            try
            {
                if (isValid)
                {
                    Database db = DatabaseFactory.CreateDatabase();
                    DbCommand dbCommand = db.GetStoredProcCommand("usp_GetDropDownItems");
                    db.AddInParameter(dbCommand, "SessionKey", DbType.String, sessionkey);

                    DataSet dsDropdowns = db.ExecuteDataSet(dbCommand);
                    if(dsDropdowns.Tables.Count > 0)
                    {
                        DataTable tDropDowns = dsDropdowns.Tables[0];
                        foreach(DataRow dr in tDropDowns.Rows)
                        {
                            Company company = new Company();
                            if (dr["CompanyID"] != DBNull.Value) { company.CompanyID = Convert.ToInt32(dr["CompanyID"]); }
                            if (dr["CompanyName"] != DBNull.Value) { company.CompanyName = dr["CompanyName"].ToString(); }
                            lstcompany.Add(company);
                            count++;
                        }
                        createproblemobj.companies = lstcompany;
                    }
                    if (dsDropdowns.Tables.Count > 1)
                    {
                        DataTable tDropDowns = dsDropdowns.Tables[1];
                        foreach (DataRow dr in tDropDowns.Rows)
                        {
                            Category category = new Category();
                            if (dr["ID"] != DBNull.Value) { category.ID = Convert.ToInt32(dr["ID"]); }
                            if (dr["Name"] != DBNull.Value) { category.Name = dr["Name"].ToString(); }
                            lstcategory.Add(category);
                            count++;
                        }
                        createproblemobj.categories = lstcategory;
                    }
                    if (dsDropdowns.Tables.Count > 2)
                    {
                        DataTable tDropDowns = dsDropdowns.Tables[2];
                        foreach (DataRow dr in tDropDowns.Rows)
                        {
                            ProductStatus productstatus = new ProductStatus();
                            if (dr["ProductStatusID"] != DBNull.Value) { productstatus.ProductStatusID = Convert.ToInt32(dr["ProductStatusID"]); }
                            if (dr["ProductStatusName"] != DBNull.Value) { productstatus.ProductStatusName = dr["ProductStatusName"].ToString(); }
                            lstproductstatus.Add(productstatus);
                            count++;
                        }
                        createproblemobj.productstatuses = lstproductstatus;
                    }
                    if (dsDropdowns.Tables.Count > 3)
                    {
                        DataTable tDropDowns = dsDropdowns.Tables[3];
                        foreach (DataRow dr in tDropDowns.Rows)
                        {
                            Country country = new Country();
                            if (dr["CountryID"] != DBNull.Value) { country.CountryID = Convert.ToInt32(dr["CountryID"]); }
                            if (dr["CountryName"] != DBNull.Value) { country.CountryName = dr["CountryName"].ToString(); }
                            if (dr["IsDefaulted"] != DBNull.Value) { country.IsDefaulted = Convert.ToBoolean(dr["IsDefaulted"].ToString()); }
                            lstcountry.Add(country);
                            count++;
                        }
                        createproblemobj.countries = lstcountry;
                    }
                    if (dsDropdowns.Tables.Count > 4)
                    {
                        DataTable tDropDowns = dsDropdowns.Tables[4];
                        foreach (DataRow dr in tDropDowns.Rows)
                        {
                            if (dr["PinCode"] != DBNull.Value) { createproblemobj.PinCode = dr["PinCode"].ToString(); }
                        }
                    }
                }
                responseObject.ResultCode = "SUCCESS";
                responseObject.ResultObjectJSON = Serializer.ObjectToJSON(createproblemobj);
                responseObject.ResultObjectRecordCount = count;
                if (responseObject.ResultObjectRecordCount == 0) { responseObject.ResultMessage = "No master items configured."; }
            }
            catch (Exception ex)
            {
                responseObject.ResultCode = "ERROR";
                responseObject.ResultMessage = ex.Message;
                CustomException exc = new CustomException(ex.ToString(), this.ToString(), "GetDropDownItems", System.DateTime.Now);
                ExceptionManager.PublishException(exc);
            }
            return (responseObject);
        }