public async Task <IActionResult> Edit(int id, [Bind("FirstName,MiddleName,LastName,Phone,DepartmentId,Id")] EmployeeCreateEditViewModel employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { var employeeIns = _mapper.Map <EmployeeCreateEditViewModel, Employee>(employee); try { _context.Update(employeeIns); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } } ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Name", employee.DepartmentId); return(View(employee)); }
protected virtual Task <int> UpdateOneAsync(T obj) { return(Task.Run(() => { _efDbContext.Update(obj); return _efDbContext.SaveChanges(); })); }
public IActionResult Edit(Game game) { if (ModelState.IsValid) { _context.Update(game); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(game)); }
public async Task <JsonResult> Edit([FromBody] AddProduct productToAdd) { if (ModelState.IsValid) { try { List <Size> prodAtr = new List <Size>(); var result = _context.Products.Include(c => c.Photos).Include(c => c.Sizes). FirstOrDefault(x => x.Id == Convert.ToInt32(productToAdd.Id)); var quantityWithoutNull = productToAdd.Quantity.Where(x => x != String.Empty).ToArray(); for (int i = 0; i < productToAdd.Size.Length; i++) { prodAtr.Add(new Size((SizeOfPruduct)Convert.ToInt32(productToAdd.Size[i]), Convert.ToInt32(quantityWithoutNull[i]))); } result.Name = productToAdd.Name; result.Price = Convert.ToDecimal(productToAdd.Price); result.Description = productToAdd.Description; result.Gender = (Gender)Enum.Parse(typeof(Gender), productToAdd.Gender); result.Group = (Group)Convert.ToInt32(productToAdd.Group); result.Sizes = prodAtr; List <Photos> photosList = new List <Photos>(); foreach (var photo in productToAdd.Photos) { photosList.Add(new Photos(photo)); } result.Photos = photosList; result.Table = productToAdd.Table; _context.Update(result); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Json(new { success = false, responseText = "Your message not sent!" })); } return(Json(new { success = true, responseText = "Your message successfuly sent!" })); } return(Json(new { success = false, responseText = "Your message not sent!" })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ProjectId,Name,Code,EmployeeId,StatusId,Contract,ContractorId,Description,EndDate")] SubProjectCreateEditViewModel subProjectDTO) { if (id != subProjectDTO.Id) { return(NotFound()); } if (ModelState.IsValid) { var subProject = _mapper.Map <SubProjectCreateEditViewModel, SubProject>(subProjectDTO); try { _context.Update(subProject); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(GetSubProject), new { projectId = subProjectDTO.ProjectId })); } catch (DbUpdateConcurrencyException) { if (!SubProjectExists(subProject.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException e) { var exception = e.InnerException; if (exception != null && exception.Message.Contains("IX_SubProjects_Name")) { ModelState.AddModelError("Name", "Подпроект уже существует"); } if (exception != null && exception.Message.Contains("IX_SubProjects_Code")) { ModelState.AddModelError("Code", "Такой код уже используется"); } } } ViewData["EmployeeId"] = new SelectList(_context.Employees .Where(x => x.Department.IsResponsibleProjectsAndSubProjects), "Id", "GetFullName"); ViewData["StatusId"] = new SelectList(_context.Statuses .Where(x => x.StatusTypeId == 1), "Id", "Name"); ViewData["ContractorId"] = new SelectList(_context.Contractors, "Id", "Name", subProjectDTO.ContractorId); return(View(subProjectDTO)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,StatusTypeId")] Status status) { if (id != status.Id) { return(NotFound()); } if (ModelState.IsValid) { if (_context.Statuses.Any(x => String.Equals(x.Name, status.Name) && x.StatusTypeId == status.StatusTypeId && x.Id != status.Id)) { ModelState.AddModelError("Name", "Такой статус уже существует"); } if (ModelState.IsValid) { try { _context.Update(status); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!StatusExists(status.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException e) { var exception = e.InnerException; if (exception != null && exception.Message.Contains("IX_Statuses_Name")) { ModelState.AddModelError("Name", "Статус уже существует"); } } } } ViewData["StatusTypeId"] = new SelectList(_context.StatusTypes, "Id", "StatusTypeName", status.StatusTypeId); return(View(status)); }
public async Task <IActionResult> Edit(int id, [Bind("Name,ProductSubTypeId,Description,Id")] ProductType productType) { if (id != productType.Id) { return(NotFound()); } if (ModelState.IsValid) { if (_context.ProductTypes.Any(x => String.Equals(x.Name, productType.Name) && x.Id != productType.Id)) { ModelState.AddModelError("Name", "Такой тип уже существует"); } if (ModelState.IsValid) { try { _context.Update(productType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!ProductTypeExists(productType.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException e) { var exception = e.InnerException; if (exception != null && exception.Message.Contains("IX_ProductTypes_Name")) { ModelState.AddModelError("Name", "Тип уже существует"); } } } } ViewData["ProductSubTypeId"] = new SelectList(_context.ProductSubTypes, "Id", "Name", productType.ProductSubTypeId); return(View(productType)); }
public async Task <IActionResult> Edit(int id, [Bind( "Name,Code,CountChanel,IsActiv,IsCommunicationDevice,NumberConnectionPoints,Description,CreatedDate,Id")] ModuleType moduleType) { if (id != moduleType.Id) { return(NotFound()); } if (ModelState.IsValid) { if (moduleType.IsActiv && !moduleType.IsCommunicationDevice) { var result = _context.ModulesTypes.Any(x => x.IsActiv && !x.IsCommunicationDevice && x.Id != moduleType.Id); if (result) { ModelState.AddModelError(string.Empty, "Уже существует действующий модуль LPBS"); return(View(moduleType)); } } try { if (moduleType.IsCommunicationDevice) { moduleType.NumberConnectionPoints = 0; } _context.Update(moduleType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ModuleTypeExists(moduleType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(moduleType)); }
public async Task <IActionResult> Edit(int id, [Bind("Name,SerialNum,CertifiedNum,ProductTypeId,SubProjectId,IsFormed,ManufacturingDate,ShippedDate,OrderDate,Id,Description")] ProductCreateViewModel productDTO) { if (id != productDTO.Id) { return(NotFound()); } if (ModelState.IsValid) { var product = _mapper.Map <ProductCreateViewModel, Product>(productDTO); try { _context.Update(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(GetProductsForSubProject), new { subProjectId = product.SubProjectId })); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException e) { var exception = e.InnerException; if (exception != null && exception.Message.Contains("IX_Products_SerialNum")) { ModelState.AddModelError("SerialNum", "Такой номер уже используется"); } // TODO причем это не выполнится за 1 операцию с предыдущим if if (exception != null && exception.Message.Contains("IX_Products_CertifiedNum")) { ModelState.AddModelError("CertifiedNum", "Такой номер уже используется"); } } } ViewData["ProductTypeId"] = new SelectList(_context.ProductTypes, "Id", "Name", productDTO.ProductTypeId); ViewData["SubProjectId"] = new SelectList(_context.SubProjects, "Id", "Name", productDTO.SubProjectId); return(View(productDTO)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,OwnerId,Code,EmployeeId,Description")] ProjectEditViewModel projectDTO) { if (id != projectDTO.Id) { return(NotFound()); } if (ModelState.IsValid) { var project = _mapper.Map <ProjectEditViewModel, Project>(projectDTO); try { _context.Update(project); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(project.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException e) { var exception = e.InnerException; if (exception != null && exception.Message.Contains("IX_Projects_Name")) { ModelState.AddModelError("Name", "Проект уже существует"); } if (exception != null && exception.Message.Contains("IX_Projects_Code")) { ModelState.AddModelError("Code", "Такой код уже используется"); } } } ViewData["EmployeeId"] = new SelectList(_context.Employees .Where(x => x.Department.IsResponsibleProjectsAndSubProjects), "Id", "GetFullName"); ViewData["OwnerId"] = new SelectList(_context.Owners, "Id", "Name", projectDTO.OwnerId); return(View(projectDTO)); }
public async Task <IQueryable <Order> > GetUserOrders(string idOfUser) { var orders = _context.Orders.Where(x => x.ApplicationUser.Id == idOfUser).Include(c => c.Products).ThenInclude(d => d.Product).ThenInclude(e => e.Photos); foreach (var item in orders) { string status = await _payULogic.GetStatusOfOrderAsync(item.OrderId); if (item.Status == Helpers.Status.New && status == "SUCCESS") { item.Status = Helpers.Status.Paid; _context.Update(orders); } } var sortedOrderList = orders.OrderByDescending(x => x.DateOfOrder); return(sortedOrderList); }
public async Task <IActionResult> Edit(int id, [Bind( "ModuleTypeId,DestinationOrderCardId,SerialNumber,Place,FirmwareVersion,EmployeeId,ActualOrderCardId,ManufacturingData,Id")] ModuleCreateEditViewModel moduleVm) { if (id != moduleVm.Id) { return(NotFound()); } if (ModelState.IsValid) { var module = _mapper.Map <ModuleCreateEditViewModel, Module>(moduleVm); try { _context.Update(module); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ModuleExists(module.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(GetModulesForCardOrder), new { cardOrderId = moduleVm.DestinationOrderCardId })); } ViewData["EmployeeId"] = new SelectList(_context.Employees .Where(x => x.Department.IsResponsibleDesignWork), "Id", "GetFullName"); ViewData["ActualOrderCardId"] = new SelectList(_context.OrderCards, "Id", "Name", moduleVm.ActualOrderCardId); ViewData["DestinationOrderCardId"] = new SelectList(_context.OrderCards, "Id", "Name", moduleVm.DestinationOrderCardId); ViewData["ModuleTypeId"] = new SelectList(_context.ModulesTypes, "Id", "Code", moduleVm.ModuleTypeId); return(View(moduleVm)); }
private void SaveProject(string projectName) { var existing = _context.Projects.SingleOrDefault(x => x.GlutProjectName == projectName); if (existing == null) { var project = new GlutProject { GlutProjectName = projectName, CreatedDateTimeUtc = _environment.SystemDateTimeUtc, ModifiedDateTimeUtc = _environment.SystemDateTimeUtc, CreatedByUserName = _environment.UserName }; _context.Add(project); } else { existing.ModifiedDateTimeUtc = _environment.SystemDateTimeUtc; _context.Update(existing); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,IsResponsibleProjectsAndSubProjects,IsResponsibleDesignWork")] Department department) { if (id != department.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(department.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException e) { var exception = e.InnerException; if (exception != null && exception.Message.Contains("IX_Departments_Name")) { ModelState.AddModelError("Name", "Отдел уже существует"); } } } return(View(department)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] Contractor contractor) { if (id != contractor.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(contractor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!ContractorExists(contractor.Id)) { return(NotFound()); } else { throw; } } catch (DbUpdateException e) { var exception = e.InnerException; if (exception != null && exception.Message.Contains("IX_Contractors_Name")) { ModelState.AddModelError("Name", "Контрагент уже существует"); } } } return(View(contractor)); }
private async Task SaveOrderToDatabase(string orderId, List <ShoppingCartItem> listOfProducts, ApplicationUser user, decimal price) { List <OrderedProduct> orderedProducts = new List <OrderedProduct>(); foreach (var item in listOfProducts) { var product = _context.Products.Where(x => x.Id == item.Product.Id).Include(c => c.Sizes).First(); OrderedProduct orderedProduct = new OrderedProduct(product, (SizeOfPruduct)Convert.ToInt32(item.Size), item.Quantity); foreach (var itema in product.Sizes) { if (itema.SizeOfPruduct == item.Size) { itema.Quantity = itema.Quantity - item.Quantity; _context.Update(itema); } } orderedProducts.Add(orderedProduct); } Order order = new Order.Builder() .DateOfOrder(DateTime.Now) .OrderId(orderId) .Products(orderedProducts) .Status(ShopFilip.Helpers.Status.New) .Price(price) .Build(); List <Order> orderList = new List <Order>(); orderList.Add(order); if (user.OrdersList == null) { user.OrdersList = new List <Order>(); } user.OrdersList.Add(order); await _userManager.UpdateAsync(user); }