// GET: SpareParts/Edit/5 public ActionResult Edit(int?id, int customerId, int machineId) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SparePart sparePart = db.SpareParts.Find(id); ViewBag.machines = db.Machines.ToList(); if (sparePart == null) { return(HttpNotFound()); } SparePartViewModel model = new SparePartViewModel { Id = sparePart.Id, Name = sparePart.Name, MachineId = machineId, CustomerId = customerId }; return(View(model)); }
public IActionResult CreateSparePart(SparePartViewModel part) { var partDto = new SparePartDto { Id = part.Id, Name = part.Name }; db.Create(partDto); return(RedirectToAction("ViewSpareParts")); }
// GET: SpareParts/Create public ActionResult Create(int?id, int customerId) { Machine machine = db.Machines.SingleOrDefault(x => x.Id == id); SparePartViewModel model = new SparePartViewModel { MachineId = machine.Id, MachineName = machine.Name, CustomerId = customerId }; return(View(model)); }
public ActionResult Edit(SparePartViewModel vm) { if (ModelState.IsValid) { SparePart sparepart = db.SpareParts.SingleOrDefault(x => x.Id == vm.Id); sparepart.Name = vm.Name; db.SpareParts.AddOrUpdate(sparepart); db.SaveChanges(); return(RedirectToAction("Details", "Machines", new { id = vm.MachineId, customerId = vm.CustomerId })); } return(View(vm)); }
public IActionResult EditSparePart(SparePartViewModel part) { if (ModelState.IsValid) { var partDto = new SparePartDto { Id = part.Id, Name = part.Name }; db.Update(partDto); return(RedirectToAction("ViewSpareParts")); } else { return(RedirectToAction("EditSparePart")); } }
public IHttpActionResult PostSparePart(SparePartViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var sparePart = Mapper.Map <SparePartViewModel, SparePart>(viewModel); sparePart.CreatedAt = DateTime.Now; UnitOfWork.Repository <SparePart>().Insert(sparePart); UnitOfWork.Save(); return(Ok()); }
public async Task <IActionResult> EditSparePart(int?id) { if (id != null) { var partDto = await db.Get(id); var part = new SparePartViewModel { Id = partDto.Id, Name = partDto.Name }; if (part != null) { return(View(part)); } } return(NotFound()); }
public async Task <ActionResult <SparePartViewModel> > GetSparePart(int partId) { var part = await dbcontext.SparePart.FindAsync(partId); if (part == null) { return(NotFound()); } var result = new SparePartViewModel { PartId = part.PartId, JobId = part.JobId, Gnr = part.Gnr, IntakeDate = part.IntakeDate, BestBeforeDate = part.BestBeforeDate }; return(Ok(result)); }
public IHttpActionResult PutSparePart(SparePartViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var sparePart = UnitOfWork.Repository <SparePart>() .Get(x => x.SparePartId == viewModel.SparePartId) .SingleOrDefault(); if (sparePart == null) { return(BadRequest()); } Mapper.Map <SparePartViewModel, SparePart>(viewModel, sparePart); sparePart.UpdatedAt = DateTime.Now; UnitOfWork.Repository <SparePart>().Update(sparePart); try { UnitOfWork.Save(); } catch (DbUpdateConcurrencyException) { if (!SparePartExists(viewModel.SparePartId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// GET: SpareParts/Delete/5 public ActionResult Delete(int?id, int customerId, int machineId) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SparePart sparePart = db.SpareParts.Find(id); if (sparePart == null) { return(HttpNotFound()); } SparePartViewModel vm = new SparePartViewModel { Id = sparePart.Id, Name = sparePart.Name, CustomerId = customerId, MachineId = machineId }; return(View(vm)); }
public async Task <ActionResult <SparePartViewModel> > CreateSparePart(int jobId, SparePart part) { var job = await dbcontext.Job.FindAsync(jobId); if (job == null) { return(NotFound()); } await dbcontext.SparePart.AddAsync(part); await dbcontext.SaveChangesAsync(); var result = new SparePartViewModel { PartId = part.PartId, JobId = part.JobId, Gnr = part.Gnr, IntakeDate = part.IntakeDate, BestBeforeDate = part.BestBeforeDate }; return(CreatedAtAction("GetSparePart", new { partId = part.PartId }, result)); }
public ActionResult Create(SparePartViewModel vm) { if (ModelState.IsValid) { SparePart sparepart = new SparePart { Name = vm.Name, FileName = vm.File.FileName }; FileData data = new FileData(); using (Stream inputStream = vm.File.InputStream) { MemoryStream memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } data.Data = memoryStream.ToArray(); } sparepart.FileData = data; Machine machine = db.Machines.SingleOrDefault(x => x.Id == vm.MachineId); machine.SpareParts.Add(sparepart); db.Machines.AddOrUpdate(machine); db.SpareParts.Add(sparepart); db.SaveChanges(); return(RedirectToAction("Details", "Machines", new { Id = vm.MachineId, customerId = vm.CustomerId })); } return(View(vm)); }
public SparePartControl() { InitializeComponent(); this.DataContext = sparePartVM = new SparePartViewModel(); }