Example #1
0
        public IActionResult Edit(FixedExpanse data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();

                var dbEntry = context.Entry(data);
                dbEntry.Property("StaffSalary").IsModified         = true;
                dbEntry.Property("StaffBhatta").IsModified         = true;
                dbEntry.Property("BhattaDetails").IsModified       = true;
                dbEntry.Property("Donation").IsModified            = true;
                dbEntry.Property("DriverRoomRent").IsModified      = true;
                dbEntry.Property("FormanSalary").IsModified        = true;
                dbEntry.Property("ExtraDriversSalary").IsModified  = true;
                dbEntry.Property("ExtraExpense").IsModified        = true;
                dbEntry.Property("ExtraExpenseDetails").IsModified = true;

                context.SaveChanges();
                ViewBag.vehicleId = new SelectList(context.Vehicle.Where(x => x.IsDeleted == false).ToList(), "Id", "VehicleNumber");
                ViewBag.result    = "Record Updated Successfully!";
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(RedirectToAction("Index"));
        }
Example #2
0
        public IActionResult Edit(DataValidation data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();

                var dbEntry = context.Entry(data);
                dbEntry.Property("Srp").IsModified       = true;
                dbEntry.Property("Prp").IsModified       = true;
                dbEntry.Property("KpkRp").IsModified     = true;
                dbEntry.Property("TaxPaper").IsModified  = true;
                dbEntry.Property("Fitness").IsModified   = true;
                dbEntry.Property("Insurance").IsModified = true;

                context.SaveChanges();
                ViewBag.result    = "Record Updated Successfully!";
                ViewBag.vehicleId = new SelectList(context.Vehicle.Where(x => x.IsDeleted == false).ToList(), "Id", "VehicleNumber");
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(RedirectToAction("Index"));
        }
Example #3
0
        public IActionResult Edit(Installment data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();

                var dbEntry = context.Entry(data);
                dbEntry.Property("VehicleId").IsModified         = true;
                dbEntry.Property("InstallmentsMonth").IsModified = true;
                dbEntry.Property("InstallmentDate").IsModified   = true;
                dbEntry.Property("InstallmentDetail").IsModified = true;
                dbEntry.Property("Amount").IsModified            = true;

                context.SaveChanges();
                ViewBag.vehicleId = new SelectList(context.Vehicle.Where(x => x.IsDeleted == false).ToList(), "Id", "VehicleNumber");

                ViewBag.result = "Record Updated Successfully!";
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(RedirectToAction("Index"));
        }
Example #4
0
        public IActionResult Edit(Department data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();

                var dbEntry = context.Entry(data);
                dbEntry.Property("DepartmentName").IsModified = true;

                context.SaveChanges();
                ViewBag.result = "Record Updated Successfully!";
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(RedirectToAction("Index"));
        }
Example #5
0
        public IActionResult Edit(Maintenance data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();

                var dbEntry = context.Entry(data);
                dbEntry.Property("StationId").IsModified       = true;
                dbEntry.Property("DepartmentId").IsModified    = true;
                dbEntry.Property("MaintenanceDate").IsModified = true;
                dbEntry.Property("Description").IsModified     = true;
                dbEntry.Property("MaintenanceDesc").IsModified = true;
                dbEntry.Property("Amount").IsModified          = true;

                context.SaveChanges();
                ViewBag.stationId   = new SelectList(context.Station.Where(x => x.StationType == "MaintenanceShop").ToList(), "Id", "Name");
                ViewBag.vehicleId   = new SelectList(context.Vehicle.Where(x => x.IsDeleted == false).ToList(), "Id", "VehicleNumber");
                ViewBag.departId    = new SelectList(context.Department.ToList(), "Id", "DepartmentName");
                ViewBag.StationType = new SelectList(new List <SelectListItem>
                {
                    new SelectListItem {
                        Selected = true, Text = "Pump", Value = "Pump"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Oil Shop", Value = "OilShop"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Maintenance Shop", Value = "MaintenanceShop"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Pickup Point", Value = "PickupPoint"
                    },
                }, "Value", "Text");
                ViewBag.cities = new SelectList(context.City.ToList(), "Id", "Name");
                ViewBag.result = "Record Updated Successfully!";
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(RedirectToAction("Index"));
        }
Example #6
0
        public IActionResult Edit(Station data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();

                var dbEntry = context.Entry(data);
                dbEntry.Property("Name").IsModified          = true;
                dbEntry.Property("Location").IsModified      = true;
                dbEntry.Property("OwnerName").IsModified     = true;
                dbEntry.Property("ContactNumber").IsModified = true;
                dbEntry.Property("StationType").IsModified   = true;
                dbEntry.Property("CityId").IsModified        = true;


                context.SaveChanges();
                ViewBag.stationtypes = new SelectList(new List <SelectListItem>
                {
                    new SelectListItem {
                        Selected = true, Text = "Pump", Value = "Pump"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Oil Shop", Value = "OilShop"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Maintenance Shop", Value = "MaintenanceShop"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Pickup Point", Value = "PickupPoint"
                    },
                }, "Value", "Text");
                ViewBag.cities = new SelectList(context.City.ToList(), "Id", "Name");
                ViewBag.result = "Record Updated Successfully!";
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(RedirectToAction("Index"));
        }
Example #7
0
        public IActionResult Edit([FromBody] Voucher data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();
                var dbEntry = context.Entry(data);
                context.Entry(data).State = EntityState.Modified;
                context.SaveChanges();
                List <int> previousExpanseIds = context.VoucherOthersExpenses
                                                .Where(ep => ep.VoucherId == data.Id)
                                                .Select(ep => ep.Id)
                                                .ToList();


                List <Voucher>              Vouchers              = context.Voucher.Where(v => v.Id == data.Id).ToList();
                List <VehicleLoading>       VehicleLoadings       = context.VehicleLoading.Where(v => v.VoucherId == data.Id).ToList();
                List <VehicleLoadingDetail> VehicleLoadingDetails = context.VehicleLoadingDetail.Where(x => x.IsDeleted == false).ToList();

                List <int> previousLoadingIds = (from vl in VehicleLoadings
                                                 join vld in VehicleLoadingDetails on vl.Id equals vld.VloadingId
                                                 select new
                {
                    vld.Id
                }
                                                 ).Select(o => o.Id).ToList();


                List <int> previousDieselIds = context.VoucherDieselDetails
                                               .Where(vl => vl.VoucherId == data.Id)
                                               .Select(vl => vl.Id)
                                               .ToList();


                List <int> currentLoadingDetailIds = new List <int>();
                //foreach (VehicleLoading itemx in data.VehicleLoading.ElementAt(0))
                //{
                VehicleLoading itemx = data.VehicleLoading.ElementAt(0);
                foreach (VehicleLoadingDetail item in itemx.VehicleLoadingDetail)
                {
                    currentLoadingDetailIds.Add(item.Id);
                }
                //}


                List <int> currentExpanseIds = data.VoucherOthersExpenses.Select(o => o.Id).ToList();

                List <int> currentDieselIds = data.VoucherDieselDetails.Select(o => o.Id).ToList();

                List <int> deletedExpanseIds       = previousExpanseIds.Except(currentExpanseIds).ToList();
                List <int> deletedDieselIds        = previousDieselIds.Except(currentDieselIds).ToList();
                List <int> deletedLoadingDetailIds = previousLoadingIds.Except(currentLoadingDetailIds).ToList();


                foreach (var ExpanseDetail in data.VoucherOthersExpenses)
                {
                    if (ExpanseDetail.Id == 0)
                    {
                        context.Entry(ExpanseDetail).State = EntityState.Added;
                        ExpanseDetail.VoucherId            = data.Id;
                    }
                    else
                    {
                        context.Entry(ExpanseDetail).State = EntityState.Modified;
                        ExpanseDetail.VoucherId            = data.Id;
                    }
                }
                foreach (var deletedExpanseId in deletedExpanseIds)
                {
                    VoucherOthersExpenses deletedExpanse = context.VoucherOthersExpenses.Where(od => od.VoucherId == data.Id && od.Id == deletedExpanseId).Single();
                    context.Entry(deletedExpanse).State = EntityState.Deleted;
                }
                context.SaveChanges();


                foreach (var DieselDetail in data.VoucherDieselDetails)
                {
                    if (DieselDetail.Id == 0)
                    {
                        context.Entry(DieselDetail).State = EntityState.Added;
                        DieselDetail.VoucherId            = data.Id;
                    }
                    else
                    {
                        context.Entry(DieselDetail).State = EntityState.Modified;
                        DieselDetail.VoucherId            = data.Id;
                    }
                }
                foreach (var deleteDieselId in deletedDieselIds)
                {
                    VoucherDieselDetails deletedDiesel = context.VoucherDieselDetails.Where(od => od.VoucherId == data.Id && od.Id == deleteDieselId).Single();
                    context.Entry(deletedDiesel).State = EntityState.Deleted;
                }



                context.SaveChanges();

                VehicleLoading Loading = data.VehicleLoading.ElementAt(0);
                //foreach (var Loading in data.VehicleLoading)
                //{
                if (Loading.Id == 0)
                {
                    Loading.VoucherId            = data.Id;
                    context.Entry(Loading).State = EntityState.Added;
                }
                else
                {
                    Loading.VoucherId            = data.Id;
                    context.Entry(Loading).State = EntityState.Detached;
                }
                foreach (var LoadingDetail in Loading.VehicleLoadingDetail)
                {
                    if (LoadingDetail.Id == 0)
                    {
                        LoadingDetail.VloadingId           = Loading.Id;
                        context.Entry(LoadingDetail).State = EntityState.Added;
                    }
                    else
                    {
                        LoadingDetail.VloadingId           = Loading.Id;
                        context.Entry(LoadingDetail).State = EntityState.Detached;
                    }
                }
                //context.Entry(Loading).State = EntityState.Modified;
                //Loading.VoucherId = data.Id;
                //}
                foreach (var deleteLoadingDetailId in deletedLoadingDetailIds)
                {
                    VehicleLoadingDetail deletedVehicleLoadingDetail = context.VehicleLoadingDetail.Where(od => od.Id == deleteLoadingDetailId).Single();

                    context.Entry(deletedVehicleLoadingDetail).State = EntityState.Deleted;
                }

                context.SaveChanges();
                ViewBag.vehicleId = new SelectList(context.Vehicle.Where(x => x.IsDeleted == false).ToList(), "Id", "VehicleNumber");
                ViewBag.result    = "**Record Updated Successfully!";
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(Json(ViewBag.result, new Newtonsoft.Json.JsonSerializerSettings()));
            //return RedirectToAction("Index");
        }
Example #8
0
        public IActionResult Edit([FromBody] Advance data)
        {
            try
            {
                var context = new RRRoadwaysDBContext();

                var dbEntry = context.Entry(data);
                context.Entry(data).State = EntityState.Modified;
                context.SaveChanges();
                //dbEntry.Property("VehicleId").IsModified = true;
                //dbEntry.Property("StationId").IsModified = true;
                //dbEntry.Property("AdvanceDate").IsModified = true;
                //dbEntry.Property("Description").IsModified = true;
                //dbEntry.Property("Amount").IsModified = true;

                List <int> previousAdvanceDetailIds = context.AdvanceDetails
                                                      .Where(ad => ad.AdvanceId == data.Id)
                                                      .Select(ep => ep.Id)
                                                      .ToList();


                List <int> currentAdvanceDetailIds = data.AdvanceDetails.Select(o => o.Id).ToList();

                List <int> deletedAdvanceDetailIds = previousAdvanceDetailIds.Except(currentAdvanceDetailIds).ToList();

                foreach (var AdvanceDetail in data.AdvanceDetails)
                {
                    if (AdvanceDetail.Id == 0)
                    {
                        context.Entry(AdvanceDetail).State = EntityState.Added;
                        AdvanceDetail.AdvanceId            = data.Id;
                    }
                    else
                    {
                        context.Entry(AdvanceDetail).State = EntityState.Modified;
                        AdvanceDetail.AdvanceId            = data.Id;
                    }
                }
                foreach (var deletedAdvanceDetailId in deletedAdvanceDetailIds)
                {
                    AdvanceDetails deletedAdvanceDetail = context.AdvanceDetails.Where(ad => ad.AdvanceId == data.Id && ad.Id == deletedAdvanceDetailId).Single();
                    context.Entry(deletedAdvanceDetail).State = EntityState.Deleted;
                }
                context.SaveChanges();

                ViewBag.vehicleId   = new SelectList(context.Vehicle.Where(x => x.IsDeleted == false).ToList(), "Id", "VehicleNumber");
                ViewBag.StationId   = new SelectList(context.Station.Where(x => x.StationType.ToLower().Contains("PickupPoint")).ToList(), "Id", "Name");
                ViewBag.StationType = new SelectList(new List <SelectListItem>
                {
                    new SelectListItem {
                        Selected = true, Text = "Pump", Value = "Pump"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Oil Shop", Value = "OilShop"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Maintenance Shop", Value = "MaintenanceShop"
                    },
                    new SelectListItem {
                        Selected = false, Text = "Pickup Point", Value = "PickupPoint"
                    },
                }, "Value", "Text");
                ViewBag.cities = new SelectList(context.City.ToList(), "Id", "Name");

                ViewBag.result = "Record Updated Successfully!";
            }
            catch (Exception e)
            {
                var error = e;
                ViewBag.error = e.Message;
            }
            return(Json(ViewBag.result, new Newtonsoft.Json.JsonSerializerSettings()));
        }