public static SelectList CarIdList(RepairCard repairCard = null) { if (null == repairCard) { return new SelectList(db.Cars, "Id", "RegistryNumber"); } return new SelectList(db.Cars, "Id", "RegistryNumber", repairCard.CarId); }
public static SelectList EmployeeIdList(RepairCard repairCard = null) { if (null == repairCard) { return new SelectList(db.Employees.Where(e => e.FirstName != "N/A"), "Id", "FirstName"); } return new SelectList(db.Employees.Where(e => e.FirstName != "N/A"), "Id", "FirstName", repairCard.EmployeeId); }
public ActionResult Create(RepairCard repairCard, string[] selectedParts) { //RepairCard repairCard = new RepairCard(); //if (TryUpdateModel(repairCard, "", null, excludeProperties: new string[] { "SpareParts", "EntryDate", "PartsPrice", "UserId", "Id" })) //{ try { repairCard.PartsPrice = 0; if (selectedParts == null) { repairCard.SpareParts = new List<SparePart>(); } else { var selectedPartsHS = new HashSet<string>(selectedParts); foreach (var sparePart in db.SpareParts) { if (selectedPartsHS.Contains(sparePart.Id.ToString())) { repairCard.SpareParts.Add(sparePart); repairCard.PartsPrice += sparePart.Price; } } repairCard.UserId = WebSecurity.CurrentUserId; repairCard.EntryDate = DateTime.Now; db.RepairCards.Add(repairCard); db.SaveChanges(); return RedirectToAction("Index"); } } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } //} ViewBag.CarId = new SelectList(db.Cars, "Id", "RegistryNumber", repairCard.CarId); ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "FirstName", repairCard.EmployeeId); ViewBag.SpareParts = db.SpareParts.ToList(); return View(repairCard); }
/// <summary> /// Create a new RepairCard object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="entryDate">Initial value of the EntryDate property.</param> /// <param name="employeeId">Initial value of the EmployeeId property.</param> /// <param name="carId">Initial value of the CarId property.</param> /// <param name="description">Initial value of the Description property.</param> /// <param name="partsPrice">Initial value of the PartsPrice property.</param> /// <param name="totalPrice">Initial value of the TotalPrice property.</param> public static RepairCard CreateRepairCard(global::System.Int32 id, global::System.DateTime entryDate, global::System.Int32 employeeId, global::System.Int32 carId, global::System.String description, global::System.Decimal partsPrice, global::System.Decimal totalPrice) { RepairCard repairCard = new RepairCard(); repairCard.Id = id; repairCard.EntryDate = entryDate; repairCard.EmployeeId = employeeId; repairCard.CarId = carId; repairCard.Description = description; repairCard.PartsPrice = partsPrice; repairCard.TotalPrice = totalPrice; return repairCard; }
/// <summary> /// Deprecated Method for adding a new object to the RepairCards EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToRepairCards(RepairCard repairCard) { base.AddObject("RepairCards", repairCard); }
private void UpdateRepairCardSpareParts(string[] selectedParts, RepairCard repairCardToUpdate) { if (selectedParts == null) { repairCardToUpdate.SpareParts = new List<SparePart>(); return; } var selectedPartsHS = new HashSet<string>(selectedParts); var repairCardSpareParts = new HashSet<int> (repairCardToUpdate.SpareParts.Select(c => c.Id)); foreach (var sparePart in db.SpareParts) { if (selectedPartsHS.Contains(sparePart.Id.ToString())) { if (!repairCardSpareParts.Contains(sparePart.Id)) { repairCardToUpdate.SpareParts.Add(sparePart); } } else { if (repairCardSpareParts.Contains(sparePart.Id)) { repairCardToUpdate.SpareParts.Remove(sparePart); } } } }
public ActionResult RepairFinish(RepairCard repaircard) { if (ModelState.IsValid) { if (repaircard.TotalPrice > repaircard.PartsPrice) { repaircard.RepairFinishDate = DateTime.Now; db.Entry(repaircard).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } } ViewBag.CarId = new SelectList(db.Cars, "Id", "RegistryNumber", repaircard.CarId); ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "FirstName", repaircard.EmployeeId); ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", repaircard.UserId); return View(repaircard); }
public void InitializeEditViewModel(RepairCard repaircard) { var allSpareParts = db.SpareParts; var repairCardParts = new HashSet<int>(repaircard.SpareParts.Select(c => c.Id)); var viewModel = new List<SelectedPartData>(); foreach (var part in allSpareParts) { viewModel.Add(new SelectedPartData { Id = part.Id, Price = part.Price, PartName = part.PartName, Selected = repairCardParts.Contains(part.Id) }); } ViewBag.SpareParts = viewModel; }
public static HashSet<int> SparePartsForCard(RepairCard repairCard) { return new HashSet<int>(repairCard.SpareParts.Select(c => c.Id)); }
public static void UpdateRepairCard(RepairCard repairCard) { db.Entry(repairCard).State = EntityState.Modified; db.SaveChanges(); }
public static void AddRepairCard(RepairCard repairCard) { db.RepairCards.Add(repairCard); db.SaveChanges(); }
public void InitializeEditViewModel(RepairCard repaircard) { var allSpareParts = RepairCardDAL.SparePartsList(); var repairCardParts = RepairCardDAL.SparePartsForCard(repaircard); var viewModel = new List<SelectedPartData>(); foreach (var part in allSpareParts) { viewModel.Add(new SelectedPartData { Id = part.Id, Price = part.Price, PartName = part.PartName, Selected = repairCardParts.Contains(part.Id) }); } ViewBag.SpareParts = viewModel; }
public ActionResult Create(RepairCard repairCard, string[] selectedParts) { try { repairCard.PartsPrice = 0; if (selectedParts == null) { repairCard.SpareParts = new List<SparePart>(); } else { var selectedPartsHS = new HashSet<string>(selectedParts); foreach (var sparePart in RepairCardDAL.ActivatedSpareCards()) { if (selectedPartsHS.Contains(sparePart.Id.ToString())) { repairCard.SpareParts.Add(sparePart); repairCard.PartsPrice += sparePart.Price; } } repairCard.RepairFinishDate = null; repairCard.TotalPrice = null; repairCard.UserId = WebSecurity.CurrentUserId; repairCard.EntryDate = DateTime.Now; RepairCardDAL.AddRepairCard(repairCard); return RedirectToAction("Index"); } } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } ViewBag.CarId = RepairCardDAL.CarIdList(repairCard); ViewBag.EmployeeId = RepairCardDAL.EmployeeIdList(repairCard); ViewBag.SpareParts = RepairCardDAL.SparePartsList(); return View(repairCard); }