public IActionResult Index(SortState sortState = SortState.NumberAsc, int page = 1) { ContainersFilterViewModel filter = HttpContext.Session.Get <ContainersFilterViewModel>(filterKey); if (filter == null) { filter = new ContainersFilterViewModel { Number = 0, TankCapacity = 0 }; HttpContext.Session.Set(filterKey, filter); } string modelKey = $"{typeof(Containers).Name}-{page}-{sortState}-{filter.Number}-{filter.TankCapacity}"; if (!cache.TryGetValue(modelKey, out ContainersViewModel model)) { model = new ContainersViewModel(); IQueryable <Containers> containers = GetSortedEntities(sortState, filter.Number, filter.TankCapacity); int count = containers.Count(); int pageSize = 10; model.PageViewModel = new PageViewModel(count, page, pageSize); model.Containers = count == 0 ? new List <Containers>() : containers.Skip((model.PageViewModel.PageNumber - 1) * pageSize).Take(pageSize).ToList(); model.SortViewModel = new SortViewModel(sortState); model.ContainersFilterViewModel = filter; cache.Set(modelKey, model); } return(View(model)); }
public async Task <IActionResult> Delete(int id, int page) { Containers containers = await context.Containers.FindAsync(id); if (containers == null) { return(NotFound()); } bool deleteFlag = false; string message = "Do you want to delete this entity"; if (context.Containers.Any(s => s.TypeOfGsmid == containers.ContainerId) && context.Containers.Any(s => s.TypeOfGsmid == containers.ContainerId)) { message = "This entity has entities, which dependents from this. Do you want to delete this entity and other, which dependents from this?"; } ContainersViewModel costsViewModel = new ContainersViewModel(); costsViewModel.Container = containers; costsViewModel.PageViewModel = new PageViewModel { PageNumber = page }; costsViewModel.DeleteViewModel = new DeleteViewModels { Message = message, IsDeleted = deleteFlag }; return(View(costsViewModel)); }
// GET: Containers/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Containers containers = db.Containers.Find(id); ContainersViewModel view = new ContainersViewModel(); view.ContainerID = containers.ContainerID; view.CompanyID = containers.CompanyID; view.ContainerTypeID = containers.ContainerTypeID; view.Name = containers.Name; view.Label = containers.Label; view.Volume = containers.Volume; view.Note = containers.Note; view.Description = containers.Description; if (containers == null) { return(HttpNotFound()); } ViewBag.CompanyID = new SelectList(db.Company, "CompanyID", "FullName", containers.CompanyID); ViewBag.ContainerTypeID = new SelectList(db.ContainerTypes, "ContainerTypeID", "Name", containers.ContainerTypeID); return(View(view)); }
public ActionResult Edit([Bind(Include = "ContainerID,ContainerTypeID,CompanyID,Name,Label,Volume,Note,Description")] ContainersViewModel ContainersViewModel) { if (ModelState.IsValid) { Containers model = db.Containers.Find(ContainersViewModel.ContainerID); model.CompanyID = ContainersViewModel.CompanyID; model.ContainerTypeID = ContainersViewModel.ContainerTypeID; model.Name = ContainersViewModel.Name; model.Label = ContainersViewModel.Label; model.Volume = ContainersViewModel.Volume; model.Note = ContainersViewModel.Note; model.Description = ContainersViewModel.Description; model.DateModified = DateTime.Now; model.ModifiedBy = Guid.Parse(User.Identity.GetUserId()); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Vehicles")); } ViewBag.CompanyID = new SelectList(db.Company, "CompanyID", "FullName", ContainersViewModel.CompanyID); ViewBag.ContainerTypeID = new SelectList(db.ContainerTypes, "ContainerTypeID", "Name", ContainersViewModel.ContainerTypeID); return(View(ContainersViewModel)); }
public IActionResult Create(int page) { ContainersViewModel costsViewModel = new ContainersViewModel(); costsViewModel.PageViewModel = new PageViewModel { PageNumber = page }; return(View(costsViewModel)); }
public async Task <IActionResult> Create(ContainersViewModel costsViewModel) { if (ModelState.IsValid) { await context.Containers.AddAsync(costsViewModel.Container); await context.SaveChangesAsync(); cache.Clean(); return(RedirectToAction("Index", "Containers")); } return(View(costsViewModel)); }
public void Insert() { // Arrange - Create a new account view model var newContainersViewModel = new ContainersViewModel() { Name = "Test Name" }; // Act - send this to the insert method on the account service logic var Response = _ContainersService.Insert(newContainersViewModel, mockUser); // Assert Assert.IsTrue(Response.Success); }
public async Task <IActionResult> Edit(int id, int page) { Containers containers = await context.Containers.FindAsync(id); if (containers != null) { ContainersViewModel costsViewModel = new ContainersViewModel(); costsViewModel.PageViewModel = new PageViewModel { PageNumber = page }; costsViewModel.Container = containers; return(View(costsViewModel)); } return(NotFound()); }
public async Task <IActionResult> Delete(ContainersViewModel costsViewModel) { bool deleteFlag = true; string message = "Do you want to delete this entity"; Containers containers = await context.Containers.FindAsync(costsViewModel.Container.ContainerId); costsViewModel.DeleteViewModel = new DeleteViewModels { Message = message, IsDeleted = deleteFlag }; if (containers == null) { return(NotFound()); } context.Containers.Remove(containers); await context.SaveChangesAsync(); cache.Clean(); return(View(costsViewModel)); }
public async Task <IActionResult> Edit(ContainersViewModel costsViewModel) { if (ModelState.IsValid) { Containers containers = context.Containers.Find(costsViewModel.Container.ContainerId); if (containers != null) { containers.Number = costsViewModel.Container.Number; containers.TankCapacity = costsViewModel.Container.TankCapacity; context.Containers.Update(containers); await context.SaveChangesAsync(); cache.Clean(); return(RedirectToAction("Index", "Containers", new { page = costsViewModel.PageViewModel.PageNumber })); } else { return(NotFound()); } } return(View(costsViewModel)); }
public async Task <IActionResult> Index(ContainersViewModel viewModel = null) { _context.ChangeTracker.LazyLoadingEnabled = false; DateTime startOf4DayWeek = new DateTime(); bool askForStartDate = true; if (viewModel?.CustomStartDate == null) { //var today = DateTime.Today; var today = new DateTime(2020, 11, 30); var difference = (today - _dayOne).Days % 8; var difference2 = (today - _dayTwo).Days % 8; var difference3 = (today - _dayThree).Days % 8; var difference4 = (today - _dayFour).Days % 8; if (difference == 0) { startOf4DayWeek = today; askForStartDate = false; } else if (difference2 == 0) { startOf4DayWeek = today.AddDays(-1); askForStartDate = false; } else if (difference3 == 0) { startOf4DayWeek = today.AddDays(-2); askForStartDate = false; } else if (difference4 == 0) { startOf4DayWeek = today.AddDays(-3); askForStartDate = false; } } else { askForStartDate = false; startOf4DayWeek = (DateTime)(viewModel?.CustomStartDate.Value); } var containers = _context.Containers .AsNoTracking() .Include(c => c.Bay) .Include(c => c.ContainerComments) .Include(c => c.Type) .Include(c => c.ContainerSuppliers) .ThenInclude(cs => cs.Supplier) .Where(c => c.ArrivalDate >= startOf4DayWeek && c.ArrivalDate < startOf4DayWeek.AddDays(5)); if (string.IsNullOrEmpty(viewModel?.ReferenceNumber) == false) { containers = containers.Where(c => c.RefNum.Contains(viewModel.ReferenceNumber)); } if (viewModel?.TypeId != 0) { containers = containers.Where(c => c.TypeId == viewModel.TypeId); } if (viewModel?.DepartmentId != 0) { containers = containers.Where(c => c.DepartmentId == viewModel.DepartmentId); } if (viewModel?.Bay != null) { containers = containers.Where(c => c.Bay.Bay == viewModel.Bay); } if (string.IsNullOrEmpty(viewModel?.Supplier) == false) { containers = containers.Where(c => c.ContainerSuppliers.Any(cs => cs.Supplier.Supplier.Equals(viewModel.Supplier))); } if (viewModel != null) { viewModel.ContainerStatuses = await _context.ContainerStatus.AsNoTracking().ToListAsync(); viewModel.ContainerTypes = await _context.ContainerTypes.AsNoTracking().ToListAsync(); viewModel.ContainerDepartments = await _context.ContainerDepartments.AsNoTracking().ToListAsync(); viewModel.Containers = await containers.ToListAsync(); viewModel.Bays = await _context.Bays.AsNoTracking().Select(b => new SelectListItem() { Value = b.Id.ToString(), Text = b.Bay.ToString() }).ToListAsync(); viewModel.Doors = await _context.Doors.AsNoTracking().Select(d => new SelectListItem() { Value = d.Id.ToString(), Text = d.Door.ToString() }).ToListAsync(); viewModel.PromptForStartDate = askForStartDate; viewModel.StartOf4DayWeekDate = startOf4DayWeek; } else { viewModel = new ContainersViewModel() { ContainerStatuses = await _context.ContainerStatus.AsNoTracking().ToListAsync(), ContainerTypes = await _context.ContainerTypes.AsNoTracking().ToListAsync(), ContainerDepartments = await _context.ContainerDepartments.AsNoTracking().ToListAsync(), Containers = await containers.ToListAsync(), Bays = await _context.Bays.AsNoTracking().Select(b => new SelectListItem() { Value = b.Id.ToString(), Text = b.Bay.ToString() }).ToListAsync(), Doors = await _context.Doors.AsNoTracking().Select(d => new SelectListItem() { Value = d.Id.ToString(), Text = d.Door.ToString() }).ToListAsync(), PromptForStartDate = askForStartDate, StartOf4DayWeekDate = startOf4DayWeek, }; } _context.ChangeTracker.LazyLoadingEnabled = true; return(View(viewModel)); }