public string insertMaintenance(AssetMaintenanceDetailDto assetMaintenance) { try { //JavaScriptSerializer json_serializer = new JavaScriptSerializer(); //var json_serializer = new JavaScriptSerializer(); //List<lstPartDetails> routes_list = json_serializer.Deserialize<List<lstPartDetails>>(assetMaintenance.Parts); GFI_AMM_VehicleMaintenance maint = dbCon.GFI_AMM_VehicleMaintenance.SingleOrDefault(c => c.URI == assetMaintenance.URI);///new GFI_AMM_VehicleMaintenance(); maint.ActualEngineHrs = assetMaintenance.ActualEngineHrs; maint.ActualOdometer = assetMaintenance.ActualOdometer; maint.AdditionalInfo = assetMaintenance.AdditionalInfo == "undefined" ? null : assetMaintenance.AdditionalInfo; maint.AssetId = assetMaintenance.AssetId; maint.AssetStatus = assetMaintenance.AssetStatus; maint.CalculatedEngineHrs = assetMaintenance.CalculatedEngineHrs; maint.CalculatedOdometer = assetMaintenance.CalculatedOdometer; maint.Comment = assetMaintenance.Comment; maint.CompanyName = assetMaintenance.CompanyName; maint.CompanyRef = assetMaintenance.CompanyRef; maint.ContactDetails = assetMaintenance.ContactDetails; maint.CoverTypeId_cbo = assetMaintenance.CoverTypeId_cbo; maint.EndDate = assetMaintenance.EndDate; maint.EstimatedValue = assetMaintenance.EstimatedValue; maint.MaintDescription = assetMaintenance.MaintDescription; maint.MaintStatusId_cbo = assetMaintenance.MaintStatusId_cbo; maint.MaintTypeId_cbo = assetMaintenance.MaintTypeId_cbo; maint.PhoneNumber = assetMaintenance.PhoneNumber; maint.StartDate = assetMaintenance.StartDate; maint.TotalCost = assetMaintenance.TotalCost; maint.VATAmount = assetMaintenance.VATAmount; maint.VATInclInItemsAmt = assetMaintenance.VATInclInItemsAmt == "undefined" ? null : assetMaintenance.VATInclInItemsAmt; maint.CreatedDate = DateTime.Now; maint.UpdatedDate = DateTime.Now; ///var mainten= dbCon.GFI_AMM_VehicleMaintenance.Add(maint); dbCon.SaveChanges(); dbCon.GFI_AMM_VehicleMaintItems.RemoveRange(dbCon.GFI_AMM_VehicleMaintItems.Where(x => x.MaintURI == maint.URI).ToList()); foreach (var item in assetMaintenance.lstParts) //for (int i = 0; i < length; i++) { GFI_AMM_VehicleMaintItems mainItems = new GFI_AMM_VehicleMaintItems(); mainItems.CreatedDate = DateTime.Now; mainItems.Description = item.Description; mainItems.ItemCode = item.ItemCode; mainItems.MaintURI = maint.URI; mainItems.Quantity = item.Quantity; mainItems.UnitCost = item.UnitCost; mainItems.UpdatedDate = item.UpdatedDate; dbCon.GFI_AMM_VehicleMaintItems.Add(mainItems); dbCon.SaveChanges(); } return(maint.URI.ToString()); } catch (Exception ex) { return(string.Empty); } }
public AssetMaintenanceDetailDto getAssetMaintenanceDetailbyID(int id, int maintId) { var result = dbCon.GFI_AMM_VehicleMaintenance.Where(c => c.URI == id).OrderByDescending(c => c.URI).Take(1).Select(c => new AssetMaintenanceDetailDto { URI = c.URI, AssetId = c.AssetId, Asset = dbCon.GFI_FLT_Asset.FirstOrDefault(d => d.AssetID == c.AssetId).AssetName, Maintenance = dbCon.GFI_AMM_VehicleMaintTypes.FirstOrDefault(d => d.MaintTypeId == c.MaintTypeId_cbo).Description, ActualOdometer = c.ActualOdometer, ActualEngineHrs = c.ActualEngineHrs, StartDate = c.StartDate, EndDate = c.EndDate, Amount = c.TotalCost, AssetNo = dbCon.GFI_FLT_Asset.FirstOrDefault(d => d.AssetID == c.AssetId).AssetNumber, Reminder = (DateTime)dbCon.GFI_AMM_VehicleMaintTypes.FirstOrDefault(d => d.MaintTypeId == c.MaintStatusId_cbo).OccurrenceFixedDate, NextMaintenance = (DateTime)c.StartDate, Category = dbCon.GFI_AMM_VehicleMaintCat.FirstOrDefault(d => d.MaintCatId == dbCon.GFI_AMM_VehicleMaintTypes.FirstOrDefault(s => s.MaintTypeId == c.MaintTypeId_cbo).MaintCatId_cbo).Description, ContactDetails = c.ContactDetails, CompanyName = c.CompanyName, PhoneNumber = c.PhoneNumber, CompanyRef = c.CompanyRef, MaintStatusId_cbo = c.MaintStatusId_cbo, AssetStatus = c.AssetStatus, CalculatedEngineHrs = c.CalculatedEngineHrs, CalculatedOdometer = c.CalculatedOdometer, Comment = c.Comment, CompanyRef2 = c.CompanyRef2, CoverTypeId_cbo = c.CoverTypeId_cbo, EstimatedValue = c.EstimatedValue, MaintDescription = c.MaintDescription, TotalCost = c.TotalCost, VATAmount = c.VATAmount, VATInclInItemsAmt = c.VATInclInItemsAmt, MaintTypeId_cbo = c.MaintTypeId_cbo, }).SingleOrDefault(); if (result != null) { result.lstParts = dbCon.GFI_AMM_VehicleMaintItems.Where(s => s.MaintURI == result.URI).Select(s => new lstPartDetails { URI = s.URI, ItemCode = s.ItemCode, Description = s.Description, Quantity = s.Quantity, UnitCost = s.UnitCost, MaintURI = s.MaintURI }).ToList(); } else { result = new AssetMaintenanceDetailDto(); } return(result); }
public ActionResult BindMaintenanceDetail(int id, int mainId, int statusId) { var obj = new MaintenanceByIdRepo(); var statusLst = new MaintenanceByStatusRepo().getMaintenanceByStatusCount(); var schduledAndCompletedStatusId = new int[] { 3, 5 }; AssetMaintenanceDetailDto model = obj.getAssetMaintenanceDetailbyID(id, mainId); if (model.Category.ToLower() == "Maintenance".ToLower() || model.Category.ToLower() == "UNPLANNED MAINTENANCE".ToLower()) { ViewBag.lstStatus = statusLst.Where(x => x.MaintStatusId == 3); } else if (statusId == 1 || statusId == 2 || statusId == 5) { ViewBag.lstStatus = statusLst.Where(x => schduledAndCompletedStatusId.Contains(x.MaintStatusId)); } else if (statusId == 3) { ViewBag.lstStatus = statusLst.Where(x => x.MaintStatusId == 5); } else if (statusId == 7) { ViewBag.lstStatus = statusLst.Where(x => x.MaintStatusId == 6); } var filePaths = Directory.GetFiles(Server.MapPath("/Uploaded_File")) .Where(f => Path.GetFileNameWithoutExtension(f).ToLower() == model.URI.ToString().ToLower()).Select(f => Path.GetFileName(f)); if (TempData["CostPartDetails"] != null) { TempData.Remove("CostPartDetails"); } TempData["CostPartDetails"] = model.lstParts; TempData.Keep("CostPartDetails"); if (filePaths.Count() > 0) { model.FileName = "~/Uploaded_File/" + filePaths.FirstOrDefault(); } return(View(model)); }
public JsonResult InsertMaintenance(AssetMaintenanceDetailDto asstMaint) { var obj = new MaintenanceByIdRepo(); asstMaint.lstParts = TempData.Peek("CostPartDetails") as List <lstPartDetails>; var statusLst = obj.insertMaintenance(asstMaint); if (string.IsNullOrEmpty(statusLst)) { return(Json("Error occured. Please try again after some time.")); } if (Request.Files.Count > 0) { var uploadFiles = Request.Files[0]; //Save File var fileContent = Request.Files[0]; if (fileContent != null && fileContent.ContentLength > 0) { // get a stream var stream = fileContent.InputStream; // and optionally write the file to disk var fileName = statusLst + Path.GetExtension(fileContent.FileName); var path = Path.Combine(Server.MapPath("~/Uploaded_File"), fileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } fileContent.SaveAs(path); } } return(Json("Record saved successfully.")); }