コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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());
        }
コード例 #3
0
 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());
 }
コード例 #4
0
        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;
                }
            }
        }
コード例 #5
0
        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)));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        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));
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        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));
        }
コード例 #22
0
        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));
        }
コード例 #23
0
        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));
        }
コード例 #24
0
        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));
        }
コード例 #25
0
        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 = "修改权限成功!" }));
        }
コード例 #26
0
        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));
        }
コード例 #27
0
ファイル: TicketsController.cs プロジェクト: CatZuniga/webCrm
        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));
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        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());
        }
コード例 #30
0
        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));
        }