Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,NormalizedName,ConcurrencyStamp")] Roles roles)
        {
            if (ModelState.IsValid)
            {
                _context.Add(roles);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(roles));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,CompanyName,Address,SiteUrl,file")] CompanyInfo CreatViewModel)
        {
            if (ModelState.IsValid)
            {
                if (CreatViewModel.file != null && CreatViewModel.file.Length > 0)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        await CreatViewModel.file.CopyToAsync(memoryStream);

                        CreatViewModel.Icon = memoryStream.ToArray();
                    }
                }
                _context.Add(CreatViewModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(CreatViewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("UserId,RoleId")] UserRoles userRoles)
        {
            try
            {
                var loginUser = _userManager.GetUserAsync(HttpContext.User);
                if (ModelState.IsValid)
                {
                    if (userRoles.UserId == null)
                    {
                        return(View());
                    }
                    if (userRoles.RoleId == null)
                    {
                        var lstUser    = _context.Users.Where(i => i.CompanyInfoID == loginUser.Result.CompanyInfoID && i.Id == userRoles.UserId);
                        var lstUserRol = _context.UserRoles.Where(i => i.UserId == userRoles.UserId);
                        ViewData["UserID"] = new SelectList(lstUser, "Id", "FullName");
                        return(View());
                    }


                    _context.Add(userRoles);
                    var result = await _context.SaveChangesAsync();
                }
                ViewData["RoleID"] = new SelectList(_context.Roles, "Id", "Name");
                ViewData["UserID"] = new SelectList(_context.Users.Where(i => i.CompanyInfoID == loginUser.Result.CompanyInfoID), "Id", "FullName");

                return(RedirectToAction("Index", null));
            }
            catch (DbUpdateException ee)
            {
                return(NotFound("Can not Creat Duplicate Role for one person"));
            }
            catch (Exception e)
            {
                return(NotFound(e));
            }
        }