public ActionResult CreateProjectWorkDescription(WorkDescription model)
        {
            model.OrganizationId = OrganizationId;
            model.CreatedDate    = System.DateTime.Now;
            model.CreatedBy      = UserID.ToString();
            var result = new WorkDescriptionRepository().InsertProjectWorkDescription(model);



            if (result.WorkDescriptionId > 0)
            {
                TempData["Success"] = "Added Successfully!";
                TempData["WorkDescriptionRefNo"] = result.WorkDescriptionRefNo;
                return(RedirectToAction("CreateProjectWorkDescription"));
            }
            else
            {
                FillVehicle();
                FillBox();
                FillFreezerUnit();
                FillItem();
                FillJobCardTaskMaster();
                WorkDescription workdescription = new WorkDescription();
                workdescription.WorkVsItems.Add(new WorkVsItem());
                workdescription.WorkVsTasks.Add(new WorkVsTask());

                TempData["error"] = "Oops!!..Something Went Wrong!!";
                TempData["RefNo"] = null;
                return(View("CreateProjectWorkDescription", model));
            }
        }
        public ActionResult EditWorkDescription(WorkDescription model)
        {
            FillVehicle();
            FillBox();
            FillFreezerUnit();
            FillItem();
            FillJobCardTaskMaster();

            ViewBag.Title        = "Edit";
            model.OrganizationId = OrganizationId;
            model.CreatedDate    = System.DateTime.Now;
            model.CreatedBy      = UserID.ToString();

            var repo = new WorkDescriptionRepository();

            var result1 = new WorkDescriptionRepository().CHECK(model.WorkDescriptionId);

            if (result1 > 0)
            {
                TempData["error"] = "Sorry!!..Already Used!!";
                TempData["WorkDescriptionRefNo"] = null;
                return(View("Edit", model));
            }

            else
            {
                try
                {
                    var result3 = new WorkDescriptionRepository().DeleteWorkDescriptionTask(model.WorkDescriptionId);
                    var result2 = new WorkDescriptionRepository().DeleteWorkDescriptionItem(model.WorkDescriptionId);
                    var result4 = new WorkDescriptionRepository().DeleteWorkDescriptionHD(model.WorkDescriptionId, UserID.ToString());
                    //string id = new WorkDescriptionRepository().InsertWorkDescription(model);
                    var result = new WorkDescriptionRepository().InsertWorkDescription(model);
                    if (result.WorkDescriptionId > 0)
                    {
                        TempData["success"] = "Updated successfully!";
                        TempData["WorkDescriptionRefNo"] = result.WorkDescriptionRefNo;
                        return(RedirectToAction("Index"));
                        //return View("Edit", model);
                    }
                    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;
                }
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult FillProjectWorkDescriptionList(int?page)
        {
            //int itemsPerPage = 2;
            int pageNumber = page ?? 1;
            var repo       = new WorkDescriptionRepository();
            var List       = repo.FillProjectWorkDescriptionList();

            return(View("ProjectWorkDescriptionList", List));
        }
        public ActionResult FillWorkDescriptionList(int?page, string vehiclemodel = "", string freezerunit = "", string box = "")
        {
            //int itemsPerPage = 2;
            int pageNumber = page ?? 1;
            var repo       = new WorkDescriptionRepository();
            var List       = repo.FillWorkDescriptionList(vehiclemodel.Trim(), freezerunit.Trim(), box.Trim());

            return(PartialView("WorkDescriptionGrid", List));
        }
        public ActionResult EditWorkDescription(int Id)
        {
            FillVehicle();
            FillBox();
            FillFreezerUnit();
            FillItem();
            FillJobCardTaskMaster();
            WorkDescription model = new WorkDescriptionRepository().GetWorkDescription(Id);

            if (model.WorkVsItems.Count == 0)
            {
                model.WorkVsItems.Add(new WorkVsItem());
            }
            if (model.WorkVsTasks.Count == 0)
            {
                model.WorkVsTasks.Add(new WorkVsTask());
            }

            return(View("Edit", model));
        }
        public ActionResult EditProjectWorkDescription(int Id)
        {
            FillItem();
            FillJobCardTaskMaster();

            WorkDescription model = new WorkDescriptionRepository().GetWorkDescription(Id);

            model.isNewInstallation = true;
            model.isProjectBased    = true;

            if (model.WorkVsItems.Count == 0)
            {
                model.WorkVsItems.Add(new WorkVsItem());
            }
            if (model.WorkVsTasks.Count == 0)
            {
                model.WorkVsTasks.Add(new WorkVsTask());
            }

            return(View("Edit", model));
        }
        public ActionResult Delete(int Id)
        {
            ViewBag.Title = "Delete";

            var result1 = new WorkDescriptionRepository().CHECK(Id);

            if (result1 > 0)
            {
                TempData["error"] = "Sorry!!..Already Used!!";
                TempData["WorkDescriptionRefNo"] = null;

                return(RedirectToAction("EditWorkDescription", new { id = Id }));
                //return RedirectToAction("Edit", new { id = Id });
            }

            else
            {
                var result3 = new WorkDescriptionRepository().DeleteWorkDescriptionTask(Id);
                var result2 = new WorkDescriptionRepository().DeleteWorkDescriptionItem(Id);
                var result4 = new WorkDescriptionRepository().DeleteWorkDescriptionHD(Id, UserID.ToString());

                if (Id > 0)
                {
                    TempData["success"] = "Deleted successfully!";
                    TempData["WorkDescriptionRefNo"] = Id;
                    return(RedirectToAction("Index"));

                    //TempData["Success"] = "Deleted Successfully!";
                    ////return RedirectToAction("PreviousList");
                    //return RedirectToAction("CreateWorkDescription");
                }

                else
                {
                    TempData["error"] = "Oops!!..Something Went Wrong!!";
                    TempData["WorkDescriptionRefNo"] = null;
                    return(RedirectToAction("Edit", new { id = Id }));
                }
            }
        }