public ActionResult GetLeads()
        {
            try
            {
                List <TextValue> lead = new List <TextValue>();
                lead = UtilityManager.GetLeadsForDropDown();

                List <SelectListItem> list = new List <SelectListItem>();
                list.Add(new SelectListItem {
                    Value = "0", Text = "Choose A Lead"
                });

                foreach (var lang in lead)
                {
                    list.Add(new SelectListItem {
                        Value = lang.Value, Text = lang.Text
                    });
                }
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                BAL.Common.LogManager.LogError("GetLeads Method", 1, Convert.ToString(ex.Source), Convert.ToString(ex.Message), Convert.ToString(ex.StackTrace));
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ManageEstimate()
        {
            //List<TextValue> category = new List<TextValue>();
            //category = UtilityManager.GetCategoriesForDropDown();

            //List<SelectListItem> list = new List<SelectListItem>();
            //list.Add(new SelectListItem { Value = "0", Text = "Choose a Category" });

            //foreach (var cat in category)
            //{
            //    list.Add(new SelectListItem { Value = cat.Value, Text = cat.Text });
            //}

            List <TextValue> lead = new List <TextValue>();

            lead = UtilityManager.GetLeadsForDropDown();

            List <SelectListItem> list1 = new List <SelectListItem>();

            list1.Add(new SelectListItem {
                Value = "0", Text = "Choose A Lead"
            });

            foreach (var leads in lead)
            {
                list1.Add(new SelectListItem {
                    Value = leads.Value, Text = leads.Text
                });
            }

            List <TextValue> client = new List <TextValue>();

            client = UtilityManager.GetClientsForDropDown();

            List <SelectListItem> list2 = new List <SelectListItem>();

            list2.Add(new SelectListItem {
                Value = "0", Text = "Choose A Client"
            });

            foreach (var clients in client)
            {
                list2.Add(new SelectListItem {
                    Value = clients.Value, Text = clients.Text
                });
            }

            //ViewBag.Category_List = list;
            ViewBag.Leads   = list1;
            ViewBag.Clients = list2;
            return(View());
        }
        public ActionResult ManageEstimate(EstimateModel model)
        {
            //List<TextValue> category = new List<TextValue>();
            //category = UtilityManager.GetCategoriesForDropDown();

            //List<SelectListItem> list = new List<SelectListItem>();
            //list.Add(new SelectListItem { Value = "0", Text = "Choose a Category" });

            //foreach (var cat in category)
            //{
            //    list.Add(new SelectListItem { Value = cat.Value, Text = cat.Text });
            //}

            List <TextValue> lead = new List <TextValue>();

            lead = UtilityManager.GetLeadsForDropDown();

            List <SelectListItem> list1 = new List <SelectListItem>();

            list1.Add(new SelectListItem {
                Value = "0", Text = "Choose A Lead"
            });

            foreach (var leads in lead)
            {
                list1.Add(new SelectListItem {
                    Value = leads.Value, Text = leads.Text
                });
            }

            List <TextValue> client = new List <TextValue>();

            client = UtilityManager.GetClientsForDropDown();

            List <SelectListItem> list2 = new List <SelectListItem>();

            list2.Add(new SelectListItem {
                Value = "0", Text = "Choose A Client"
            });

            foreach (var clients in client)
            {
                list2.Add(new SelectListItem {
                    Value = clients.Value, Text = clients.Text
                });
            }

            objResponse Response = new objResponse();

            try
            {
                session = new SessionHelper();
                Project.Entity.Estimate objEstimate = new Entity.Estimate();
                objEstimate.Date         = BAL.Helper.Helper.ConvertToDateNullable(model.Date, "dd/MM/yyyy");
                objEstimate.Lead_ID_Fk   = model.Lead_ID_Fk;
                objEstimate.Client_ID_Fk = model.Client_ID_Fk;
                objEstimate.Priority     = model.Priority;
                objEstimate.Category     = model.Category;
                objEstimate.Language     = model.Language;
                objEstimate.AssignTo     = model.AssignTo;
                objEstimate.Requirment   = model.Requirment;

                Response = objEstimateManager.AddEstimate(objEstimate, session.UserSession.Username);

                if (Response.ErrorCode == 0)
                {
                    long Estimate_ID = Convert.ToInt64(Response.ResponseData.Tables[0].Rows[0][0]);
                    // Uploading Requirment Document and Saving Details to DB
                    try
                    {
                        foreach (HttpPostedFileBase file in model.UploadedDoc)
                        {
                            if (file != null)
                            {
                                string filename = System.IO.Path.GetFileName(file.FileName);
                                Debug.WriteLine("file name is: " + filename);
                                string[] fileext = filename.Split('.');

                                // string newFileName = "EST0" + Estimate_ID + "_" + filename + "." + fileext[1];
                                string newFileName = "EST0" + Estimate_ID + "_" + filename;
                                string newFilePath = Server.MapPath(ConfigurationManager.AppSettings["Estimation_Req_Dir"]) + newFileName;
                                file.SaveAs(newFilePath);

                                if (filename != "")
                                {
                                    Response = objEstimateManager.AddEstimationUpload(Estimate_ID, filename, session.UserSession.Username, 0);
                                    if (Response.ErrorCode == 0)
                                    {
                                        return(RedirectToRoute("EstimateHome"));
                                    }
                                    else
                                    {
                                        if (System.IO.File.Exists(newFilePath))
                                        {
                                            System.IO.File.Delete(newFilePath);
                                        }
                                        ViewBag.Error_Msg = "Unable To Upload Document. Please go to update Estimate and upload document again.";
                                        //  ViewBag.Category_List = list;
                                        ViewBag.Leads   = list1;
                                        ViewBag.Clients = list2;
                                        return(View());
                                    }
                                }
                            }
                            else
                            {
                                return(RedirectToRoute("EstimateHome"));
                            }
                        }

                        // If we got this far , than there is something wrong. Redirect to LeadsHome Page
                        return(RedirectToRoute("EstimateHome"));
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Error_Msg = ex.Message.ToString();
                        // ViewBag.Category_List = list;
                        ViewBag.Leads   = list1;
                        ViewBag.Clients = list2;
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Error_Msg = Response.ErrorMessage;
                    //  ViewBag.Category_List = list;
                    ViewBag.Leads   = list1;
                    ViewBag.Clients = list2;
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error_Msg = Response.ErrorMessage;
                // ViewBag.Category_List = list;
                ViewBag.Leads   = list1;
                ViewBag.Clients = list2;
                BAL.Common.LogManager.LogError("ManageEstimate Post Method", 1, Convert.ToString(ex.Source), Convert.ToString(ex.Message), Convert.ToString(ex.StackTrace));
                return(View());
            }
        }