コード例 #1
0
        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());
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
ファイル: GameController.cs プロジェクト: the-s-a-m/ScoreApp
        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());
        }
コード例 #4
0
ファイル: ShotController.cs プロジェクト: Reijei/FootballDevi
        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());
        }
コード例 #5
0
        public async Task <IActionResult> CreateEvent(Event @event)
        {
            _context.Add(@event);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        public async Task Add(T entity)
        {
            // await Context.AddAsync(entity);
            await Context.Set <T>().AddAsync(entity);

            await Context.SaveChangesAsync();
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        public async Task <IActionResult> AddPost(Post post)
        {
            await _context.Posts.AddAsync(post);

            var result = await _context.SaveChangesAsync();

            return(RedirectToAction("ManagePost", "Manage"));
        }
コード例 #11
0
        /// <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();
        }
コード例 #12
0
        //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);
        }
コード例 #13
0
 private async Task CheckClientAsync(User user)
 {
     if (!dc.Clients.Any())
     {
         dc.Clients.Add(new Client {
             User = user
         });
         await dc.SaveChangesAsync();
     }
 }
コード例 #14
0
        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();
        }
コード例 #15
0
        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));
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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());
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        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));
        }
コード例 #22
0
        public async Task <IActionResult> Create(Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
コード例 #23
0
 private async Task CheckManagerAsync(User manager)
 {
     if (!_dataContext.Managers.Any())
     {
         _dataContext.Managers.Add(new Manager
         {
             User = manager
         });
         await _dataContext.SaveChangesAsync();
     }
 }
コード例 #24
0
ファイル: LadataController.cs プロジェクト: cmatskas/dfedemo
        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));
        }
コード例 #25
0
        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));
        }
コード例 #26
0
        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));
        }
コード例 #27
0
        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));
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        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));
        }
コード例 #30
0
        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));
        }