Exemple #1
0
        public ActionResult Delete(string Id)
        {
            int id = Convert.ToInt32(Id);
            DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1();

            DSRCManagementSystem.Models.Transportation objmodel = new DSRCManagementSystem.Models.Transportation();

            //var value = objdb.ManageExpense_Mapping.Where(x => x.VehicleId == id).Select(o => o.ManageExpenseId).FirstOrDefault();

            //var objvalue = objdb.ManageExpenses.Where(x => x.ManageExpenseId == id && x.Isactive == true).Select(o => o).FirstOrDefault();
            //// var type = objdb.Master_ExpenseType.Where(x => x.ExpenseType_Id == objvalue.ExpenseType).Select(o => o.ExpenseType).FirstOrDefault();

            //objvalue.Isactive = false;



            var objvalue = objdb.ManageExpenses.Where(x => x.ManageExpenseId == id && x.Isactive == true).Select(o => o).FirstOrDefault();
            // var type = objdb.Master_ExpenseType.Where(x => x.ExpenseType_Id == objvalue.ExpenseType).Select(o => o.ExpenseType).FirstOrDefault();
            var values = objdb.ManageExpense_Mapping.Where(x => x.ManageExpenseId == objvalue.ManageExpenseId).Select(o => o).FirstOrDefault();

            objdb.ManageExpense_Mapping.DeleteObject(values);
            objvalue.Isactive = false;



            objdb.SaveChanges();



            return(Json(new { Result = "Success", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public ActionResult AddExpense(DSRCManagementSystem.Models.Transportation objmodel)
        {
            DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1();

            DSRCManagementSystem.ManageExpens objexp = new DSRCManagementSystem.ManageExpens();

            DSRCManagementSystem.ManageExpense_Mapping objmap = new DSRCManagementSystem.ManageExpense_Mapping();

            //var num =Convert.ToInt32(objmodel.VehicleNumber);

            var vehicleid = objdb.Vehicles.Where(x => x.Vehicle_No == objmodel.VehicleNumber && x.IsActive == true).Select(o => o.VehicleId).FirstOrDefault();

            var objalready = objdb.ManageExpense_Mapping.Where(x => x.VehicleId == vehicleid).Select(o => o.ManageExpenseId).ToList();


            if (objalready != null)
            {
                for (int i = 0; i < objalready.Count(); i++)
                {
                    var value   = Convert.ToInt32(objalready[i]);
                    int?already = objdb.ManageExpenses.Where(x => x.ManageExpenseId == value && x.Isactive == true).Select(o => o.ExpenseType).FirstOrDefault();

                    if (already == Convert.ToInt32(objmodel.ExpenseType))
                    {
                        return(Json(new { Result = "Already", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet));
                    }
                }
            }


            objexp.Date        = DateTime.Now;
            objexp.Cost        = objmodel.Cost;
            objexp.ExpenseType = Convert.ToInt32(objmodel.ExpenseType);
            objexp.Isactive    = true;
            objdb.AddToManageExpenses(objexp);
            objdb.SaveChanges();


            objmap.ManageExpenseId = objexp.ManageExpenseId;
            objmap.VehicleId       = vehicleid;
            objdb.AddToManageExpense_Mapping(objmap);
            objdb.SaveChanges();



            return(Json(new { Result = "Success", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        public ActionResult EditExpense(DSRCManagementSystem.Models.Transportation objmodel)
        {
            DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1();

            DSRCManagementSystem.Models.Transportation obj = new DSRCManagementSystem.Models.Transportation();
            var vehicle_num = objmodel.VehicleNumber;
            var dbvalue     = objdb.Vehicles.Where(x => x.Vehicle_No == vehicle_num).Select(o => o.VehicleId).FirstOrDefault();
            // var dbvalue = objdb.Vehicles.Where(x => x.Vehicle_No == vehicle_num).Select(o => o).FirstOrDefault();
            var objmanageexpmap = objdb.ManageExpense_Mapping.Where(x => x.VehicleId == dbvalue).Select(o => o.ManageExpenseId).FirstOrDefault();

            if (objmodel.ExpenseId != null)
            {
                var manageid  = objdb.ManageExpenses.Where(x => x.ManageExpenseId == objmanageexpmap && x.Isactive == true).Select(o => o).FirstOrDefault();
                var listvalue = objdb.ManageExpense_Mapping.Where(x => x.VehicleId == dbvalue).Select(o => o.ManageExpenseId).ToList();

                if (manageid.ExpenseType != Convert.ToInt32(objmodel.ExpenseType))
                {
                    if (listvalue != null)
                    {
                        for (int k = 0; k < listvalue.Count(); k++)
                        {
                            var dbvalue1    = Convert.ToInt32(listvalue[k]);
                            var alreadyvale = objdb.ManageExpenses.Where(x => x.ManageExpenseId == dbvalue1 && x.Isactive == true).Select(o => o.ExpenseType).FirstOrDefault();
                            if (alreadyvale == Convert.ToInt32(objmodel.ExpenseType))
                            {
                                return(Json(new { Result = "Already", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet));
                            }
                        }
                    }
                }


                manageid.Date        = objmodel.dateofyear;
                manageid.Cost        = objmodel.Cost;
                manageid.ExpenseType = Convert.ToInt32(objmodel.ExpenseType);
                objdb.SaveChanges();
            }

            else
            {
                DSRCManagementSystem.ManageExpens          objexp = new DSRCManagementSystem.ManageExpens();
                DSRCManagementSystem.ManageExpense_Mapping objmap = new DSRCManagementSystem.ManageExpense_Mapping();
                objexp.Date        = objmodel.dateofyear;
                objexp.Cost        = objmodel.Cost;
                objexp.ExpenseType = Convert.ToInt32(objmodel.ExpenseType);
                objexp.Isactive    = true;
                objdb.AddToManageExpenses(objexp);
                objdb.SaveChanges();



                objmap.ManageExpenseId = objexp.ManageExpenseId;

                //objmap.VehicleId = Convert.ToInt32(dbvalue.VehicleId);

                objmap.VehicleId = Convert.ToInt32(dbvalue);

                objdb.AddToManageExpense_Mapping(objmap);
                objdb.SaveChanges();
            }

            return(Json(new { Result = "Success", URL = @Url.Action("AlertPopUp", "Popup") }, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        public ActionResult EditExpense(string Id, string vehicleno)
        {
            int id           = 0;
            int objvehicleno = 0;

            if (Id != "" && Id != null)
            {
                id = Convert.ToInt32(Id);
            }
            else
            {
                id = 0;
            }



            DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1();

            DSRCManagementSystem.Models.Transportation objmodel = new DSRCManagementSystem.Models.Transportation();


            var vehicles = (from p in objdb.Vehicles.Where(x => x.IsActive == true || x.IsActive == null)
                            select new
            {
                VehicleId = p.VehicleId,
                VehicleNo = p.Vehicle_No,
            }).ToList();

            var expense = (from p in objdb.Master_ExpenseType
                           select new
            {
                Id6 = p.ExpenseType_Id,
                Expense = p.ExpenseType
            }).ToList();



            var num      = objdb.ManageExpense_Mapping.Where(x => x.ManageExpenseId == id).Select(o => o.VehicleId).FirstOrDefault();
            var objvalue = objdb.ManageExpenses.Where(x => x.ManageExpenseId == id && x.Isactive == true).Select(o => o).FirstOrDefault();

            if (objvalue != null)
            {
                objmodel.Cost = objvalue.Cost;
            }
            else
            {
                objmodel.Cost = null;
            }

            if (objvalue != null)
            {
                if (objvalue.Date != null)
                {
                    DateTime d1 = Convert.ToDateTime(objvalue.Date);
                    string   d  = d1.ToShortDateString();
                    objmodel.date       = d;
                    objmodel.dateofyear = objvalue.Date;
                }
                else
                {
                    DateTime d1 = Convert.ToDateTime(DateTime.Now.ToString());
                    string   d  = d1.ToShortDateString();
                    objmodel.date       = d;
                    objmodel.dateofyear = objvalue.Date;
                }
            }

            else
            {
                objmodel.date = null;
            }


            objmodel.ExpenseId = id;


            if (num != null)
            {
                ViewBag.Vehicles = new SelectList(vehicles, "VehicleId", "VehicleNo", num);
            }
            else
            {
                if (vehicleno != "" && Id == "")
                {
                    int vechi  = Convert.ToInt32(vehicleno);
                    var objnum = objdb.Vehicles.Where(x => x.VehicleId == vechi).Select(o => o.VehicleId).FirstOrDefault();
                    ViewBag.Vehicles = new SelectList(vehicles, "VehicleId", "VehicleNo", objnum);
                }
                else
                {
                    ViewBag.Vehicles = new SelectList(vehicles, "VehicleId", "VehicleNo");
                }
            }

            int?expensetype = 0;

            if (objvalue != null)
            {
                expensetype = objvalue.ExpenseType;
            }


            if (objvalue != null)
            {
                ViewBag.Expense = new SelectList(expense, "Id6", "Expense", expensetype);
            }
            else
            {
                ViewBag.Expense = new SelectList(expense, "Id6", "Expense");
            }


            return(View(objmodel));
        }