public async Task <IActionResult> Post([FromBody] SubdivisionViewModel vm) { if (vm == null) { return(BadRequest()); } Subdivision parent = null; List <Subdivision> children = null; if (vm.Parent != null) { parent = await db.Subdivisions.FirstOrDefaultAsync(s => s.Id == vm.Parent.Id); } if (vm.Children != null) { children = db.Subdivisions.Where(s => vm.Children.Any(c => c.Id == s.Id)).ToList(); } var subdivision = vm.ToSubdivision(parent, children); db.Subdivisions.Add(subdivision); await db.SaveChangesAsync(); return(Ok()); }
public DeleteSubdivisionCommand(SubdivisionViewModel subdivisionViewModel, ISubdivisionRepository repository) { _subdivisionViewModel = subdivisionViewModel; _repository = repository; _subdivisionViewModel.PropertyChanged += (sender, args) => CanExecuteChanged?.Invoke(this, EventArgs.Empty); }
public RefreshSubdivisionsCommand(SubdivisionViewModel subdivisionViewModel, ISubdivisionRepository subdivisionRepository, IEmployeeRepository employeeRepository) { _subdivisionViewModel = subdivisionViewModel; _subdivisionRepository = subdivisionRepository; _employeeRepository = employeeRepository; }
public async Task <IActionResult> Add([FromBody] SubdivisionViewModel viewModel) { try { var subdivision = await _subdivisionUseCases.Add(_mapper.Map <Subdivision>(viewModel), GetUserId()); return(Ok(new { subdivision.Id })); } catch (BadRequestException e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> CreateSubdivision() { var model = new SubdivisionViewModel(); var departemns = await _context.Department.ToListAsync(); var categoryes = await _context.Category.ToListAsync(); model.Departments = departemns; model.Categoryes = categoryes; return(View(model)); }
public async Task <IActionResult> Update( [FromRoute] Guid subdivisionId, [FromBody] SubdivisionViewModel viewModel) { try { var subdivision = _mapper.Map <Subdivision>(viewModel); subdivision.Id = subdivisionId; var updatedSubdivision = await _subdivisionUseCases.Update(subdivision, GetUserId()); return(Ok(updatedSubdivision)); } catch (NotFoundException e) { return(NotFound(e.Message)); } }
public async Task <IActionResult> Get(int id) { var subdivision = await db.Subdivisions.FirstOrDefaultAsync(s => s.Id == id); if (subdivision == null) { return(Content(JsonConvert.SerializeObject(null, new JsonSerializerSettings { Formatting = Formatting.Indented }))); } db.Entry(subdivision).Collection(s => s.Children).Load(); var vm = new SubdivisionViewModel(subdivision); return(Content(JsonConvert.SerializeObject(vm, new JsonSerializerSettings { Formatting = Formatting.Indented }))); }
public async Task <IActionResult> CreateSubdivision(SubdivisionViewModel model) { if (model != null) { var reserv = new Reserve { Name = "Резерв " + model.Name }; var battlecrew = new BattleСrew { Name = "Боевой расчет " + model.Name }; var warehouse = new Warehouse { Name = "Склад" + model.Name }; await _context.Reserve.AddAsync(reserv); await _context.BattleСrew.AddAsync(battlecrew); await _context.Warehouse.AddAsync(warehouse); await _context.SaveChangesAsync(); var result = new Subdivision { Name = model.Name, CategoryesId = model.CategoryesId, CountCarInBattleCrew = model.CountCar, DepartmentId = model.DepartmentId, BattleСrewId = battlecrew.BattleСrewId, BattleСrew = battlecrew, ReservId = reserv.ReserveId, Reserve = reserv, WarehouseId = warehouse.WarehouseId, Warehouse = warehouse }; await _context.Subdivision.AddAsync(result); await _context.SaveChangesAsync(); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Put(int id, [FromBody] SubdivisionViewModel vm) { if (vm == null) { return(BadRequest()); } if (!db.Employees.Any(u => u.Id == id)) { return(NotFound()); } var parent = await db.Subdivisions.FirstOrDefaultAsync(s => s.Id == vm.Parent.Id); var children = db.Subdivisions.Where(s => vm.Children.Any(c => c.Id == s.Id)).ToList(); var subdivision = vm.ToSubdivision(parent, children); db.Update(subdivision); await db.SaveChangesAsync(); return(Ok()); }
public AddSubdivisionCommand(SubdivisionViewModel subdivisionViewModel) { _subdivisionViewModel = subdivisionViewModel; }
public SaveSubdivisionsCommand(SubdivisionViewModel subdivisionViewModel, ISubdivisionRepository repository) { _subdivisionViewModel = subdivisionViewModel; _repository = repository; }