public async Task <IActionResult> Create(User user) { try { var user1 = await _context.User.AsNoTracking().FirstOrDefaultAsync(m => m.Login == user.Login); if (user1 == null) { user.Password = HashPassword(user.Password); user.IsDeleted = 0; _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError("", "Login is taken"); return(View(user)); } } catch (Exception) { ModelState.AddModelError("", "Login is taken"); return(View(user)); } }
public async Task <IActionResult> CreateOrderAsync([FromBody] Orders_ProductsCreateDto dto) { var id = Convert.ToInt32(User.Identity.Name); //新增订单 var order = mapper.Map <Orders>(dto.OrderCreateDto); order.CreateID = id; order.CreateTime = DateTime.Now; order.OrderNo = Guid.NewGuid().ToString(); await context.Orders.AddAsync(order); await context.SaveChangesAsync(); var customer = await context.Customers.FindAsync(order.CustomerID); if (customer == null) { return(NotFound()); } if (customer.IsReal == 0) { customer.IsReal = 1; context.Customers.Update(customer); await context.SaveChangesAsync(); } //新增订单产品记录 List <Orders_Products> orders_Products = new List <Orders_Products>(); foreach (var item in dto.ProductsCreateDtos) { Orders_Products orders_Products1 = new Orders_Products(); orders_Products1.ProductID = item.ID; orders_Products1.ProductTitle = item.Title; orders_Products1.Num = item.Number; orders_Products1.CreateID = id; orders_Products1.CreateTime = DateTime.Now; orders_Products1.OrderID = order.ID; orders_Products.Add(orders_Products1); } try { await context.Orders_Products.AddRangeAsync(orders_Products); await context.SaveChangesAsync(); } catch (Exception) { throw; } return(Ok()); }
public async Task <ActionResult <int> > AddMenu(string MName, string URL, string Remark, int PId, int Sort, string cb) { db.MenuInfo.Add(new MenuInfo { MName = MName, URL = URL, Remark = Remark, PId = PId, Sort = Sort }); return(await db.SaveChangesAsync()); }
public async Task <bool> UpdateContactAsync(ViewContactLess model) { using (var transaction = _database.Database.BeginTransaction()) { try { var original = await _database.Contacts.FirstOrDefaultAsync(p => p.GuID == model.GuID); var replace = new Contact(); AutoMapper.Mapper.Map(model, replace); replace.ContactId = original.ContactId; replace.DateModified = DateTime.UtcNow; _database.Entry(original).CurrentValues.SetValues(replace); await _database.SaveChangesAsync(); transaction.Commit(); return(true); } catch { transaction.Rollback(); throw; } } }
public async Task <IActionResult> DeleteConfirmed(int id) { var order = await _context.Orders.SingleOrDefaultAsync(m => m.Id == id); _context.Orders.Remove(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,Description,DateTime,ComType")] Communication communication) { if (ModelState.IsValid) { _context.Add(communication); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(communication)); }
public async Task <IActionResult> Create([Bind("TangibleProductId,Manufacture,Model,EndOfLife,ID,Price")] TangibleProduct tangibleProduct) { if (ModelState.IsValid) { _context.Add(tangibleProduct); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tangibleProduct)); }
public async Task <IActionResult> Create([Bind("Id,Summary,Description,status,OpenDateTime,CloseDateTime")] Conversation conversation) { if (ModelState.IsValid) { _context.Add(conversation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(conversation)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,PhoneNumber,EmailAddress")] CSOEmployee cSOEmployee) { if (ModelState.IsValid) { _context.Add(cSOEmployee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cSOEmployee)); }
public async Task <IActionResult> Create([Bind("Id,WarrantyExpiry,discount")] OrderItem orderItem) { if (ModelState.IsValid) { _context.Add(orderItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(orderItem)); }
public async Task <IActionResult> Create([Bind("ID,BuildingName,PropertyNumber,AddressLine1,AddressLine2,AddressLine3,PostCode")] Address address) { if (ModelState.IsValid) { _context.Add(address); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(address)); }
public async Task <IActionResult> Create([Bind("ID,Price")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("Id,Name,Requisites")] Partner partner) { if (ModelState.IsValid) { _context.Add(partner); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(partner)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Vendor vendor) { if (ModelState.IsValid) { _context.Add(vendor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vendor)); }
public async Task <IActionResult> Create([Bind("Id,OrderDate,Discount")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public async Task <IActionResult> Create([Bind("ID,Name,SetupDate,CostCenterCode")] Client client) { if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(client)); }
public async Task <IActionResult> Create([Bind("Id")] InternalEmployee internalEmployee) { if (ModelState.IsValid) { _context.Add(internalEmployee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(internalEmployee)); }
public async Task <IActionResult> Create([Bind("ID,Username,Password,Tipo")] Usuario usuario) { if (ModelState.IsValid) { _context.Add(usuario); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(usuario)); }
public async Task <IActionResult> Create([Bind("Id,Name,Red,Green,Blue")] CarColor carColor) { if (ModelState.IsValid) { _context.Add(carColor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(carColor)); }
public async Task <IActionResult> Create([Bind("Id,Article,Name,Price")] PartType partType) { if (ModelState.IsValid) { _context.Add(partType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(partType)); }
public async Task <IActionResult> Create([Bind("ServiceProductId,Summary,DurationDays,ID,Price")] ServiceProduct serviceProduct) { if (ModelState.IsValid) { _context.Add(serviceProduct); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(serviceProduct)); }
public async Task <IActionResult> Create([Bind("Id,StartDate,EndDate,WarrantyExpiry,discount")] ClientService clientService) { if (ModelState.IsValid) { _context.Add(clientService); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(clientService)); }
public async Task <IActionResult> Create(Note note) { if (ModelState.IsValid) { note.IsDeleted = 0; _context.Add(note); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(note)); }
public async Task <IActionResult> Create([Bind("Id,Name,EngineCapacity,EngineType,DriveUnitType,TransmissionType,VendorId")] CarModel carModel) { if (ModelState.IsValid) { _context.Add(carModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateVendorsDropDownList(carModel.VendorId); return(View(carModel)); }
public async Task <IActionResult> EditPermissionsDtoesByRoleIDAsync(int roleID, string permissionIDs) { if (roleID == 0) { return(Ok(new { code = 1, msg = "请先选中角色,再为其更改权限!" })); } var tokenid = Convert.ToInt32(User.Identity.Name); //根据角色ID获取对应的权限记录 var roles_Permissions = await wrapperRepository.Role_PermissionRepository.GetRoles_PermissionsByRoleID(roleID); //删除角色全部的权限记录 context.Roles_Permissions.RemoveRange(roles_Permissions); await context.SaveChangesAsync(); //查询到角色信息 Roles role = await context.Roles.FindAsync(roleID); List <Roles_Permissions> roles_PermissionsAddList = new List <Roles_Permissions>(); //遍历重新添加权限记录 foreach (var id in permissionIDs.Split(",")) { var permission = await context.Permissions.FindAsync(Convert.ToInt32(id)); Roles_Permissions roles_Permission = new Roles_Permissions(); roles_Permission.CreateID = tokenid; roles_Permission.CreateTime = DateTime.Now; roles_Permission.RoleID = roleID; roles_Permission.RoleName = role.Name; roles_Permission.PermissionID = permission.ID; roles_Permission.PermissionName = roles_Permission.PermissionName; roles_PermissionsAddList.Add(roles_Permission); } await context.Roles_Permissions.AddRangeAsync(roles_PermissionsAddList); await context.SaveChangesAsync(); //请掉所有角色权限菜单的缓冲 foreach (var item in await context.Roles.ToListAsync()) { await distributedCache.RemoveAsync($"Role_Menu_{item.ID}"); } return(Ok(new { code = 0, msg = "修改权限成功!" })); }
public async Task <IActionResult> Create([Bind("ID,Nombre,Cedula,Pagina_Web,Direccion,Telefono,Sector,IDUsuario")] Cliente cliente) { if (ModelState.IsValid) { cliente.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); _context.Add(cliente); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cliente)); }
public async Task <IActionResult> Create([Bind("ID,Titulo,Detalle,Quien_reporto,Estado_Actual,IDCliente,IDUsuario")] Ticket ticket) { if (ModelState.IsValid) { ticket.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); _context.Add(ticket); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDCliente"] = new SelectList(_context.Cliente, "IDCliente", "Nombre", ticket.IDCliente); return(View(ticket)); }
public async Task <IActionResult> Create([Bind("ID,Titulo,DiaHora,Virtual,IDCliente,IDUsuario")] Reunion reunion) { if (ModelState.IsValid) { reunion.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); _context.Add(reunion); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDCliente"] = new SelectList(_context.Cliente, "IDCliente", "Nombre", reunion.IDCliente); return(View(reunion)); }
public async Task <IActionResult> AddRoleAsync([FromBody] RoleCreateDto roleDto) { var id = Convert.ToInt32(User.Identity.Name); var roles = mapper.Map <Roles>(roleDto); roles.CreateID = id; roles.CreateTime = DateTime.Now; await context.Roles.AddAsync(roles); await context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Create([Bind("ID,Nombre,Apellidos,Correo,Telefono,Puesto,IDCliente,IDUsuario")] Contacto contacto) { if (ModelState.IsValid) { contacto.IDUsuario = Convert.ToInt32(HttpContext.Session.GetInt32("userid")); _context.Add(contacto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDCliente"] = new SelectList(_context.Cliente, "IDCliente", "Nombre", contacto.IDCliente); return(View(contacto)); }