public async Task <T> Add(T entity)
        {
            _context.Add <T>(entity);
            await _context.SaveChangesAsync();

            return(Get(entity.ID));
        }
예제 #2
0
        public async Task <IActionResult> PutSample(int id, Sample sample)
        {
            if (id != sample.SampleId)
            {
                return(BadRequest());
            }

            _context.Entry(sample).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SampleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,StartDate,FinishDate,Priority,ManagerId,CustomerId,PerformerId")] Project project)
        {
            if (id != project.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try {
                    _context.Update(project);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException) {
                    if (!ProjectExists(project.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            var companies = _context.Companies.ToList();
            var employees = _context.Employees.ToList();

            ViewData["CustomerId"]  = new SelectList(companies, "Id", "Name", project.CustomerId);
            ViewData["PerformerId"] = new SelectList(companies, "Id", "Name", project.PerformerId);
            ViewData["ManagerId"]   = new SelectList(employees, "Id", "Surname", project.ManagerId);
            return(View(project));
        }
예제 #4
0
        public virtual async Task <Result <int> > AddAsync(TDomainEntity entity)
        {
            var dbEntity = mapper.Map <TDBEntity>(entity);

            Context.Set <TDBEntity>().Add(dbEntity);
            await Context.SaveChangesAsync();

            return(Result <int> .GetSuccessInstance(entity.ID));
        }
        public async Task <AuthenticationResultModel> AuthenticateAsync(UsersMaster user)
        {
            // authentication successful so generate jwt token
            AuthenticationResultModel authenticationResult = new AuthenticationResultModel();
            var tokenHandler = new JwtSecurityTokenHandler();

            try
            {
                var key = Encoding.ASCII.GetBytes(_appSettings.JwtSettings.Secret);

                ClaimsIdentity Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim("UserId", user.UserId.ToString()),
                    new Claim("FirstName", user.FirstName),
                    new Claim("LastName", user.LastName),
                    new Claim("EmailId", user.Email == null?"":user.Email),
                    new Claim("UserName", user.UserName == null?"":user.UserName),
                    new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                });
                foreach (var item in GetUserRole(user.UserId))
                {
                    Subject.AddClaim(new Claim(ClaimTypes.Role, item.RoleName));
                }

                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject            = Subject,
                    Expires            = DateTime.UtcNow.Add(_appSettings.JwtSettings.TokenLifetime),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                };
                var token = tokenHandler.CreateToken(tokenDescriptor);

                authenticationResult.Token = tokenHandler.WriteToken(token);


                var refreshToken = new RefreshToken
                {
                    Token        = Guid.NewGuid().ToString(),
                    JwtId        = token.Id,
                    UserId       = user.UserId,
                    CreationDate = DateTime.UtcNow,
                    ExpiryDate   = DateTime.UtcNow.AddMonths(6)
                };
                await _context.RefreshTokens.AddAsync(refreshToken);

                await _context.SaveChangesAsync();

                authenticationResult.RefreshToken = refreshToken.Token;
                authenticationResult.Success      = true;
                return(authenticationResult);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("Id,Name,StartDate")] Project project)
        {
            if (ModelState.IsValid)
            {
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
        public async Task <IActionResult> AddCompany([Bind("Id,Name")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(Redirect("~/Projects/SelectCompanies"));
            }
            return(Redirect("~/Projects/SelectCompanies"));
        }
예제 #9
0
        public async Task <Result <int> > Save()
        {
            var result = await _context.SaveChangesAsync();

            return(Result <int> .GetSuccessInstance(result));
        }
예제 #10
0
        public async Task AddAsync(Player player)
        {
            await _context.AddAsync(player);

            await _context.SaveChangesAsync();
        }
예제 #11
0
        public async Task Create(T entity)
        {
            await _pmContext.Set <T>().AddAsync(entity);

            await _pmContext.SaveChangesAsync();
        }