public async Task <IActionResult> PutPlayer(int id, Player player) { if (id != player.PlayerID) { return(BadRequest()); } _context.Entry(player).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlayerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task CollectFeeAsync(Account account, decimal fee) { using (var dbContextTransaction = _dataDbContext.Database.BeginTransaction()) { var entity = _dataDbContext.Accounts.Single(x => string.Equals(x.IBAN, account.AccountName)); entity.Balance = account.Balance; entity.UpdatedAt = SystemDateTime.UtcNow(); var transaction = new TransactionEntity { FromId = entity.Id, Amount = fee, CreateAt = entity.UpdatedAt, Type = TransactionType.Withdraw, Status = OperationStatus.Ok, AccountTo = "SYSTEM" }; _dataDbContext.Transactions.Add(transaction); await _dataDbContext.SaveChangesAsync(); dbContextTransaction.Commit(); } }
public async Task <IActionResult> PutGame([FromRoute] long id, [FromBody] Game game) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != game.ID || GameDeleted(id)) { return(BadRequest()); } dbContext.Entry(game).State = EntityState.Modified; try { await dbContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutShot(int?id, Shot shot) { if (id != shot.ShotID) { return(BadRequest()); } _context.Entry(shot).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShotExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> CreateEvent(Event @event) { _context.Add(@event); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.Id) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutValue(int id, Value value) { if (id != value.Id) { return(BadRequest()); } _context.Entry(value).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ValueExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task Add(T entity) { // await Context.AddAsync(entity); await Context.Set <T>().AddAsync(entity); await Context.SaveChangesAsync(); }
public static async Task SeedDataAsync(DataDbContext context, ILoggerFactory loggerFactory) { try { var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (!context.Articles.Any()) { var articlesData = File.ReadAllText(path + @"/Data/SeedData/Source/articles.json"); var articles = JsonSerializer.Deserialize <List <Article> >(articlesData); foreach (var item in articles) { context.Articles.Add(item); } await context.SaveChangesAsync(); } if (!context.Comments.Any()) { var commentData = File.ReadAllText(path + @"/Data/SeedData/Source/comments.json"); var comments = JsonSerializer.Deserialize <List <Comment> >(commentData); foreach (var item in comments) { context.Comments.Add(item); } await context.SaveChangesAsync(); } } catch (Exception ex) { var logger = loggerFactory.CreateLogger <StoreContextSeed>(); logger.LogError(ex.Message); } }
public async Task <IActionResult> AddPost(Post post) { await _context.Posts.AddAsync(post); var result = await _context.SaveChangesAsync(); return(RedirectToAction("ManagePost", "Manage")); }
/// <summary> /// Delete content having name in the list of <paramref name="internalCaptions"/>. /// </summary> /// <param name="internalCaptions">List of content captions to delete by.</param> public async Task DeleteContentsByInternalCaptionsAsync(IReadOnlyList <string> internalCaptions) { var contentsToRemove = from x in _context.Content where internalCaptions.Contains(x.InternalCaption) select x; _context.Content.RemoveRange(contentsToRemove); await _context.SaveChangesAsync(); }
//counting likes public async Task <int> ResolveLikes(int id) { var c = await _context.posts.FirstAsync(a => a.id == id); c.Likes = await _context.like.CountAsync(b => b.post == id); await _context.SaveChangesAsync(); return(c.Likes); }
private async Task CheckClientAsync(User user) { if (!dc.Clients.Any()) { dc.Clients.Add(new Client { User = user }); await dc.SaveChangesAsync(); } }
public async Task Add(T entity) { entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; // await Context.AddAsync(entity); await Context.Set <T>().AddAsync(entity); await Context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("Id,CountryName")] Country country) { if (ModelState.IsValid) { _context.Add(country); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task <IActionResult> Create([Bind("Id,Nom,Prenom,Telephone")] ContactModel contactModel) { if (ModelState.IsValid) { _context.Add(contactModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(contactModel)); }
public async Task <IActionResult> Create([Bind("Id,Address,City,PhoneNumber")] Shop shop) { if (ModelState.IsValid) { _context.Add(shop); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(shop)); }
public async Task <IActionResult> CreateClass(AddOrUpdateClassDto addClass) { var classEntity = _mapper.Map <Class>(addClass); classEntity.Id = Guid.NewGuid(); _context.Class.Add(classEntity); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Create([Bind("Id,MaterialName")] Material material) { if (ModelState.IsValid) { _context.Add(material); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(material)); }
public async Task <IActionResult> Create([Bind("Id,Name,Cost,Count,IdBrandInstrument,IdMaterialInstrument,IdCountryInstrument,IdInstrumentTypeInstrument,IdShopInstrument")] Instrument instrument) { if (ModelState.IsValid) { _context.Add(instrument); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(instrument)); }
public async Task <IActionResult> Create([Bind("Id,Count,InstrumentCheque,CustomerCheque")] Cheque cheque) { if (ModelState.IsValid) { _context.Add(cheque); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cheque)); }
public async Task <IActionResult> Create(Client client) { if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(client)); }
private async Task CheckManagerAsync(User manager) { if (!_dataContext.Managers.Any()) { _dataContext.Managers.Add(new Manager { User = manager }); await _dataContext.SaveChangesAsync(); } }
public async Task <IActionResult> Create([Bind("Name")] Ladata ladata) { if (ModelState.IsValid) { _context.Add(ladata); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ladata)); }
public async Task <IActionResult> Create([Bind("Id,InstrumentTypeName")] InstrumentType instrumentType) { if (ModelState.IsValid) { _context.Add(instrumentType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(instrumentType)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,FixedPhone,Email,CellPhone,Address")] 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,Firstname,Surname,Email")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("Id,Name,MiddleName,Surame")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("id,Name,Descripcion,Slung")] City city) { if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Create([Bind("Id,Name,MiddleName,Surame,IdShopStaff,IdJobStaff")] Staff staff) { if (ModelState.IsValid) { _context.Add(staff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(staff)); }