public async Task <IActionResult> CreateLineBalancing(ParticularLineBalancing particularLineBalancing) { var loggedInUser = await _userManager.FindByNameAsync(HttpContext.User.Identity.Name); if (ModelState.IsValid) { ParticularLineBalancing tempLineBalancing = new ParticularLineBalancing(); tempLineBalancing.LineId = particularLineBalancing.LineId; tempLineBalancing.StandardOperationTimeId = particularLineBalancing.StandardOperationTimeId; tempLineBalancing.Who = particularLineBalancing.Who; _context.Add(tempLineBalancing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(AllLines))); } var Sots = _context.StandardOperationTimes .Include(m => m.SotModel) .Where(m => m.FactoryId == loggedInUser.FactoryId) .ToList(); var linesToCreateParticularLineBalanging = new List <Line>(); var lines = await _context.Lines.Where(m => m.Section.FactoryId == loggedInUser.FactoryId).ToListAsync(); var particularLineBalancings = await _context.ParticularLineBalancings.Where(m => m.Line.Section.FactoryId == loggedInUser.FactoryId).ToListAsync(); foreach (var line in lines) { bool isCreated = false; foreach (var tempParticularLineBalancing in particularLineBalancings) { if (line.Id == tempParticularLineBalancing.LineId) { isCreated = true; } } if (isCreated == false) { linesToCreateParticularLineBalanging.Add(line); } } ViewData["LineId"] = new SelectList(linesToCreateParticularLineBalanging, "Id", "LineNumber"); ViewData["StandardOperationTimes"] = Sots; return(View(particularLineBalancing)); }
public async Task <IActionResult> EditLineBalancing(int id, ParticularLineBalancing particularLineBalancing) { if (id != particularLineBalancing.Id) { return(NotFound()); } if (ModelState.IsValid) { var tempLineBalancing = await _context.ParticularLineBalancings .Where(m => m.Id == id) .FirstOrDefaultAsync(); tempLineBalancing.LineId = particularLineBalancing.LineId; tempLineBalancing.StandardOperationTimeId = particularLineBalancing.StandardOperationTimeId; tempLineBalancing.Who = particularLineBalancing.Who; tempLineBalancing.ActualLineBalancingRatio = particularLineBalancing.ActualLineBalancingRatio; _context.Update(tempLineBalancing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(AllLines))); } ViewData["ParticularLineBalancing"] = particularLineBalancing; var loggedInUser = await _userManager.FindByNameAsync(HttpContext.User.Identity.Name); var Sots = _context.StandardOperationTimes .Include(m => m.SotModel) .Where(m => m.FactoryId == loggedInUser.FactoryId) .ToList(); ViewData["StandardOperationTimes"] = Sots; return(View(particularLineBalancing)); }