public ActionResult Edit(string type, int id = 0)
        {
            try
            {
                FillDropdowns();
                if (id != 0)
                {
                    QuerySheet QuerySheet = new QuerySheet();
                    var        repo       = new ProjectCostRepository();

                    QuerySheet       = new QuerySheetRepository().GetQuerySheetItem(id);
                    QuerySheet.Items = repo.GetProjectCost(id);
                    ViewBag.Type     = type;
                    return(View(QuerySheet));
                }
                else
                {
                    TempData["error"] = "That was an invalid/unknown request. Please try again.";
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (InvalidOperationException iox)
            {
                TempData["error"] = "Sorry, we could not find the requested item. Please try again.|" + iox.Message;
            }
            catch (SqlException sx)
            {
                TempData["error"] = "Some error occured while connecting to database. Please try again after sometime.|" + sx.Message;
            }
            catch (NullReferenceException nx)
            {
                TempData["error"] = "Some required data was missing. Please try again.|" + nx.Message;
            }
            catch (Exception ex)
            {
                TempData["error"] = "Some error occured. Please try again.|" + ex.Message;
            }

            TempData["success"] = "";
            return(RedirectToAction("Index", new { Type = "Unit" }));
        }
        public ActionResult CreateQuerySheet(QuerySheet qs)
        {
            //if (qs.QuerySheetId==0)
            //{
            try
            {
                qs.OrganizationId = OrganizationId;
                qs.CreatedDate    = System.DateTime.Now;
                qs.CreatedBy      = UserID.ToString();
                var id = "";
                int row;
                if (qs.Type == "Unit")
                {
                    FillDropdowns();
                    row = new QuerySheetRepository().UpdateQuerySheetUnit(qs);
                    TempData["success"] = "Saved Successfully (" + qs.QuerySheetRefNo + ")";
                    return(RedirectToAction("PendingQuerySheetforUnit"));
                }
                else if (qs.Type == "Costing")
                {
                    FillDropdowns();
                    if (qs.Items == null || qs.Items.Count <= 0)
                    {
                        TempData["error"] = "Query Sheet cannot be saved without costing parameters.";
                        return(RedirectToAction("CreateQuerySheetUnit", new { QuerySheetid = qs.QuerySheetId, type = "Costing" }));
                    }
                    row = new ProjectCostRepository().InsertProjectCosting(qs);
                    TempData["success"] = "Saved Successfully (" + qs.QuerySheetRefNo + ")";
                    return(RedirectToAction("PendingQuerySheetforCosting"));
                }
                else if (qs.Type == "RoomDetails")
                {
                    id = new QuerySheetRepository().InsertQuerySheet(qs);


                    if (id.Split('|')[0] != "0")
                    {
                        qs.QuerySheetId     = Convert.ToInt16(id.Split('|')[0]);
                        qs.QuerySheetRefNo  = id.Split('|')[1];
                        TempData["success"] = "Saved successfully.  Reference No. is " + id.Split('|')[1];
                        TempData["error"]   = "";
                        return(RedirectToAction("CreateQuerySheet", new { type = qs.Type }));
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            catch (SqlException sx)
            {
                TempData["error"] = "Some error occured while connecting to database. Please check your network connection and try again.|" + sx.Message;
            }
            catch (NullReferenceException nx)
            {
                TempData["error"] = "Some required data was missing. Please try again.|" + nx.Message;
            }
            catch (Exception ex)
            {
                TempData["error"] = "Some error occured. Please try again.|" + ex.Message;
            }
            TempData["success"] = "";
            //}
            return(RedirectToAction("CreateQuerySheet", new { type = qs.Type }));
        }
 public ProjectCostsController(ApplicationDbContext context, ProjectCostRepository repository)
 {
     _context       = context;
     CostRepository = repository;
 }