public async Task LogAsync(CommandContext context, DiscordChannel channel) { var config = await _databaseContext.GuildConfigs .Where(e => e.GuildId == context.Guild.Id) .FirstOrDefaultAsync(); if (config == null) { config = new GuildConfig { Prefix = ".", GuildId = context.Guild.Id }; await _databaseContext.AddAsync(config); } if (channel == null) { config.LogChannel = null; await context.RespondAsync("Log channel has been cleared."); } else { config.LogChannel = channel.Id; await context.RespondAsync($"Log channel set to {channel.Mention}"); } await _databaseContext.SaveChangesAsync(); }
public virtual async Task <T> InsertAsync(T entity) { var result = await Context.AddAsync(entity); await Context.SaveChangesAsync(); return(result.Entity); }
public async Task <IComment> addComment(IComment comment) { comment.date = DateTime.Now; await _usersRepository.AddAsync(comment); await _usersRepository.SaveChangesAsync(); return(comment); }
public async Task <IActionResult> LoginResult() { var result = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); if (result.Succeeded) { string email = result.Principal.Identities.First().Claims .Where(claim => claim.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress") .Select(claim => claim.Value).FirstOrDefault(); User user = _context.Users.FirstOrDefault(u => u.Email == email); if (user is null) { user = new User { UserId = email.Split('@')[0], Email = email, DateCreated = DateTime.Now, Token = GenerateToken() }; await _context.AddAsync(user); await _context.SaveChangesAsync(); } return(Redirect("/")); } return(RedirectToAction(nameof(Login))); }
public async Task <Churrasco> Add(ChurrascoAddDto churrascoAddDto) { Churrasco churrasco = new Churrasco { DataChurras = churrascoAddDto.DataChurras, Motivo = churrascoAddDto.Motivo, Observacoes = churrascoAddDto.Observacoes }; if (churrascoAddDto.ValorSugerido <= 0) { churrasco.ValorSugerido = decimal.Parse(_configuration["ValorSugerido"]); churrasco.ValorSugeridoSemBebida = churrasco.ValorSugerido - 10; } else if (churrascoAddDto.ValorSugerido < 10) { churrasco.ValorSugeridoSemBebida = 0; } else { churrasco.ValorSugeridoSemBebida = churrascoAddDto.ValorSugerido - 10; } await _context.AddAsync(churrasco); return(churrasco); }
public async Task <BasicResponseInfo> Handle(RegisterUserRequest request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.Username) || string.IsNullOrEmpty(request.Password)) { return(new BasicResponseInfo(false, HttpStatusCode.BadRequest, "Required 'Username' and 'Password'.")); } var isUserExist = _databaseContext.SystemUsers.Any(x => x.Username == request.Username); if (isUserExist) { return(new BasicResponseInfo(false, HttpStatusCode.Conflict, "User already exists!")); } var userSalt = _saltGeneratorUtility.Generate(); var password = _userPasswordUtility.HashPassword(request.Password, userSalt); var newUser = new SystemUser() { Username = request.Username, Salt = userSalt, Password = password }; await _databaseContext.AddAsync(newUser).ConfigureAwait(false); await _databaseContext.SaveChangesAsync().ConfigureAwait(false); return(new BasicResponseInfo(true, HttpStatusCode.Created, "User added.")); }
public async Task <long> CreateComment(CommentObject comObj, long postId) { var post = await _database.Posts.FirstOrDefaultAsync(i => i.Id == postId); if (post == null) { return(-1); } var comment = new Comment() { Author = comObj.Author, Text = comObj.Text, CreateDate = DateTime.Now, PostId = postId, Post = post }; post.CommentCount++; await _database.AddAsync(comment); await _database.SaveChangesAsync(); return(comment.Id); }
public async Task <ActionResult> Create(AnimeSeries series) { if (!ModelState.IsValid) { return(NotFound()); } AnimeSeries findExisting = await _context.AnimeSeries. Include(p => p.Picture). Include(se => se.SeasonsEpisodes). FirstOrDefaultAsync(s => s.EnglishTitle.Equals(series.EnglishTitle, StringComparison.OrdinalIgnoreCase) || s.JapaneseName.Equals(series.JapaneseName, StringComparison.OrdinalIgnoreCase )); if (findExisting == null) { var asyncAdded = _context.AddAsync(new AnimeSeries().ToModel(series)); if (asyncAdded.IsCompletedSuccessfully) { await _context.SaveChangesAsync(); return(Ok(new BasicResponse { Success = true })); } } return(Ok(new BasicResponse { Success = false, Error = "Series already exists" })); }
public async Task <ShoppingCart> GetShoppingCart() { var loggedUser = _httpContextAccessor.HttpContext.User; var userId = _userManager.GetUserId(loggedUser); var applicationUser = await _context.Users .Include(sc => sc.ShoppingCart) .ThenInclude(i => i.Items) .ThenInclude(m => m.MobilePhoneRef) .FirstOrDefaultAsync(u => u.Id == userId); if (applicationUser == null) { return(null); } if (applicationUser.ShoppingCart == null) { var sc = new ShoppingCart() { Id = Guid.NewGuid().ToString() }; applicationUser.ShoppingCart = sc; applicationUser.ShoppingCardId = sc.Id; _context.Update(applicationUser); await _context.AddAsync(sc); await _context.SaveChangesAsync(); } return(applicationUser.ShoppingCart); }
public async Task <IActionResult> PayU_Redirect(string amount) { if (!string.IsNullOrEmpty(amount)) { var results = await PaymentService.CreateOrder(amount); // retry if no response if (string.IsNullOrEmpty(results)) { await PaymentService.GetAccessToken(); results = await PaymentService.CreateOrder(amount); } // if still no response if (string.IsNullOrEmpty(results)) { return(RedirectToAction("Error", "Payment")); } var separatedResults = results.Split(";"); await _context.AddAsync(new Models.OrderModel { Id = separatedResults[1], UserModelId = AuthService.GetJWTAudience(HttpContext.Session.GetString("TOKEN")) }); await _context.SaveChangesAsync(); return(Redirect(separatedResults[0])); } return(RedirectToAction("Index", "Home")); }
public async Task AddAsync(TEntity entity) { using var context = new DatabaseContext(); await context.AddAsync(entity); await context.SaveChangesAsync(); }
public async Task <ChoiceGetData> PostAsync(ChoicePostData data) { using var connection = authService.Connection; var optionsArray = data.Options.Split(",").Select(o => o.Trim()).ToArray(); if (optionsArray.Length < 2) { throw new Exception("At least 2 options are required."); } string optionsString = string.Join(",", optionsArray); var entity = new ChoiceEntity() { Name = data.Name.Trim(), Options = optionsString, UserId = authService.UserId }; var context = new DatabaseContext(connection); await context.AddAsync(entity); await context.SaveChangesAsync(); await connection.CloseAsync(); return(CreateGetDataFromEntity(entity)); }
public async Task CreateWebhooks(Project project) { var webhooks = new List <Webhook>(); var actions = new[] { "Push", "Delete" }; foreach (var action in actions) { var result = await _githubService.CreateWebhook(project, action); if (result.ErrorMessage != null) { _toastService.ShowToast(result.ErrorMessage, ToastLevel.Error); return; } var webhook = new Webhook { Id = result.Response.id, Name = result.Response.name, Type = result.Response.type, Url = result.Response.config.url, ProjectId = project.Id, }; webhooks.Add(webhook); } foreach (var wh in webhooks) { await _databaseContext.AddAsync(wh); } await _databaseContext.SaveChangesAsync(); }
public async Task <string> AddOrder(ShoppingCartVM shoppingCartVM, string userId, int shippingAddressId) { if (shoppingCartVM.Items.Count == 0) { return("-1"); } var order = new Order() { ApplicationUserId = userId, Id = Guid.NewGuid().ToString(), ShippingAddressId = shippingAddressId }; await _context.AddAsync(order); await _context.SaveChangesAsync(); foreach (var item in shoppingCartVM.Items) { var orderItem = new OrderMobilePhone() { OrderRef = order, OrderId = order.Id, MobilePhoneId = item.MobilePhoneId, MobilePhoneRef = item.MobilePhoneRef, Quantity = item.Quantity }; order.Items.Add(orderItem); } _context.Update(order); await _context.SaveChangesAsync(); return(order.Id); }
public static async Task <byte[]> EncryptPassword(string password, string userId, DatabaseContext _context) { using var deriveBytes = new Rfc2898DeriveBytes(password, PBKDF2[0], PBKDF2[1]); var salt = new SaltModel { UserModelId = userId, Value = deriveBytes.Salt }; var key = deriveBytes.GetBytes(PBKDF2[0]); var userSalt = await _context.Salts.Where(s => s.UserModelId == userId).FirstOrDefaultAsync(); if (userSalt != null) { userSalt.Value = salt.Value; _context.Entry(userSalt).State = EntityState.Modified; } else { await _context.AddAsync(salt); } return(key); }
public async Task <BasicResponseInfo> Handle(CreateMailingGroupRequest request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.Name)) { return(new BasicResponseInfo(false, HttpStatusCode.BadRequest, $"Mailing group name is undefined.")); } var existingMailingGroup = _databaseContext .MailingGroups .Where(x => x.SystemUserId == request.UserId) .Any(x => x.Name == request.Name); if (existingMailingGroup) { return(new BasicResponseInfo(false, HttpStatusCode.Conflict, $"The operation has been rolled back. Mailing group name '{request.Name}' has already added.")); } var newMailingGroup = new MailingGroup() { Name = request.Name, SystemUserId = request.UserId }; await _databaseContext.AddAsync(newMailingGroup).ConfigureAwait(false); await _databaseContext.SaveChangesAsync().ConfigureAwait(false); return(new BasicResponseInfo(true, HttpStatusCode.Created, $"Success. Mailing group with name '{request.Name}' added.")); }
public async Task AddCommander(Commander commander) { await _context.AddAsync(commander); await _context.SaveChangesAsync(); await Task.CompletedTask; }
public async Task AddReport(Report report) { await _context.AddAsync(report); await _context.SaveChangesAsync(); await Task.CompletedTask; }
public async Task AddLeave(Leave leave) { await _context.AddAsync(leave); await _context.SaveChangesAsync(); await Task.CompletedTask; }
public async Task <string> CreateMatch(Match match) { await _databaseContext.AddAsync(match); await _databaseContext.SaveChangesAsync(); return(match.Id); }
public async Task <ActionResult <Car> > AddCar([FromBody] Car _car) { await _db.AddAsync <Car>(_car); await _db.SaveChangesAsync(); return(CreatedAtAction(nameof(GetById), new { id = _car.CarID }, _car)); }
public async Task AddSoldier(Soldier soldier) { await _context.AddAsync(soldier); await _context.SaveChangesAsync(); await Task.CompletedTask; }
public async Task <LibraryType> Add(LibraryType libraryType) { await _context.AddAsync(libraryType); await _context.SaveChangesAsync(); throw new NotImplementedException(); }
public async Task AddCompany(Company company) { await _context.AddAsync(company); await _context.SaveChangesAsync(); await Task.CompletedTask; }
public async Task <IActionResult> AddUserAsync([FromBody] UserModel userDetails) { await _databaseContext.AddAsync(userDetails); await _databaseContext.SaveChangesAsync(); return(Ok(true)); }
/// <summary> /// Adds and returns a new blacklist filter /// </summary> /// <param name="regex">The Regex pattern to use</param> /// <param name="guild">The guild to use</param> /// <returns>The newly added filter</returns> public async Task <BlacklistFilter> AddBlacklistFilter(string regex, IGuild guild) { var entry = await _dbContext.AddAsync(new BlacklistFilter { Content = regex, ServerId = guild.Id }); await _dbContext.SaveChangesAsync(); return(entry.Entity); }
public virtual async Task <T> AddAsync(T entity) { await DbContext.AddAsync(entity); await DbContext.SaveChangesAsync(); return(entity); }
public async Task AddAdmin(Admin admin) { await _context.AddAsync(admin); await _context.SaveChangesAsync(); await Task.CompletedTask; }
public async Task <Product> Post([FromBody] Product product) { await _context.AddAsync(product); await _context.SaveChangesAsync(); return(product); }
public async Task <User> Add(User user) { await _context.AddAsync(user); await _context.SaveChangesAsync(); throw new NotImplementedException(); }