예제 #1
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));
        }
예제 #2
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));
        }