public async Task <IActionResult> AddAvto() { AvtoViewModel avtoViewModel = new AvtoViewModel() { brandlist = await _context.brands.Include(e => e.manufacturer).ToListAsync(), departmass = await _context.departments.ToListAsync() }; return(View(avtoViewModel)); }
public async Task <IActionResult> AddAvto(string action, AvtoViewModel model, int brandl, int depart) { if (action == "AddBrand") { return(RedirectToAction("AddBrand", "AddSome")); } else if (action == "Save Change") { avto a = new avto() { additional_info = model.additional_info, brand = _context.brands.Where(e => e.brand_key == brandl).FirstOrDefault(), Brand_Key = brandl, cancelletion_date = model.cancelletion_date, color = model.color, department = _context.departments.Where(e => e.Department_Key == depart).FirstOrDefault(), Department_Key = depart, namber = model.namber, receipt_date = DateTime.Now, year_of_release = model.year_of_release }; byte[] imageData = null; if (model.imageget != null) { using (var binaryReader = new BinaryReader(model.imageget.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)model.imageget.Length); } a.image_byte = imageData; } _context.avtoes.Add(a); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } AvtoViewModel avtoViewModel = new AvtoViewModel() { brandlist = await _context.brands.Include(e => e.manufacturer).ToListAsync(), departmass = await _context.departments.ToListAsync() }; return(View(avtoViewModel)); }
public async Task <IActionResult> CancelAvto(int Id_sold, string action, AvtoViewModel model) { if (action == "Accept Cancellation") { var a = await _context.avtoes. Include(e => e.repairs).ThenInclude(e => e.work_data).ThenInclude(e => e.worker). Include(e => e.repairs).ThenInclude(e => e.work_data).ThenInclude(e => e.profession). Include(e => e.repairs).ThenInclude(e => e.type_of_repair). Include(e => e.department). Include(e => e.avto_worker).ThenInclude(e => e.work_data).ThenInclude(e => e.worker). Include(e => e.avto_worker).ThenInclude(e => e.work_data).ThenInclude(e => e.profession). Include(e => e.avto_worker).ThenInclude(e => e.divisions).ThenInclude(e => e.way). Include(e => e.brand).ThenInclude(e => e.manufacturer). Include(e => e.brand).ThenInclude(e => e.type_of_avto). Where(e => e.Avto_Key == model.Avto_Key).FirstOrDefaultAsync(); a.when_cancellation = model.when_cancellation; _context.Update(a); await _context.SaveChangesAsync(); return(RedirectToAction("ShowAvto", "Shows", new { id = model.Avto_Key })); } else if (action == "Accept Sold") { var a = await _context.avtoes. Include(e => e.repairs).ThenInclude(e => e.work_data).ThenInclude(e => e.worker). Include(e => e.repairs).ThenInclude(e => e.work_data).ThenInclude(e => e.profession). Include(e => e.repairs).ThenInclude(e => e.type_of_repair). Include(e => e.department). Include(e => e.avto_worker).ThenInclude(e => e.work_data).ThenInclude(e => e.worker). Include(e => e.avto_worker).ThenInclude(e => e.work_data).ThenInclude(e => e.profession). Include(e => e.avto_worker).ThenInclude(e => e.divisions).ThenInclude(e => e.way). Include(e => e.brand).ThenInclude(e => e.manufacturer). Include(e => e.brand).ThenInclude(e => e.type_of_avto). Where(e => e.Avto_Key == model.Avto_Key).FirstOrDefaultAsync(); a.when_sell = model.when_sell; a.sell_cost = model.sell_cost; _context.Update(a); await _context.SaveChangesAsync(); return(RedirectToAction("ShowAvto", "Shows", new { id = model.Avto_Key })); } return(View(AvtoViewModel.AvtoViewReturn(Id_sold, _context))); }
public IActionResult EditAvto(int Id_edit, AvtoViewModel model, string action, string typeofa, string depart, int brandl) { if (action == "Save Change") { var a = _context.avtoes. Include(e => e.repairs).ThenInclude(e => e.work_data).ThenInclude(e => e.worker). Include(e => e.repairs).ThenInclude(e => e.work_data).ThenInclude(e => e.profession). Include(e => e.repairs).ThenInclude(e => e.type_of_repair). Include(e => e.department). Include(e => e.avto_worker).ThenInclude(e => e.work_data).ThenInclude(e => e.worker). Include(e => e.avto_worker).ThenInclude(e => e.work_data).ThenInclude(e => e.profession). Include(e => e.avto_worker).ThenInclude(e => e.divisions).ThenInclude(e => e.way). Include(e => e.brand).ThenInclude(e => e.manufacturer). Include(e => e.brand).ThenInclude(e => e.type_of_avto). Where(e => e.Avto_Key == model.Avto_Key).FirstOrDefault(); a.brand = _context.brands.Where(e => e.brand_key == brandl).FirstOrDefault(); a.Brand_Key = brandl; a.color = model.color; a.namber = model.namber; a.additional_info = model.additional_info; a.year_of_release = model.year_of_release; a.department = _context.departments.Where(e => e.Department_Key == Convert.ToInt32(depart)).FirstOrDefault(); a.Department_Key = a.department.Department_Key; a.Avto_Key = model.Avto_Key; byte[] imageData = null; if (model.imageget != null) { using (var binaryReader = new BinaryReader(model.imageget.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)model.imageget.Length); } a.image_byte = imageData; } _context.avtoes.Update(a); _context.SaveChanges(); return(RedirectToAction("ShowAvto", "Shows", new { id = a.Avto_Key })); } return(View(AvtoViewModel.AvtoViewReturn(Id_edit, _context))); }
public IActionResult ShowAvto(int id) { return(View(AvtoViewModel.AvtoViewReturn(id, _context))); }