示例#1
0
        public async Task <IActionResult> PutPlayers(int id, Players players)
        {
            if (id != players.PlayerId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutSport(int id, Sport sport)
        {
            if (id != sport.SportId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#3
0
        public async Task <IHttpActionResult> PutBookRecord(Guid id, BookRecord bookRecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bookRecord.RecordId)
            {
                return(BadRequest());
            }

            db.Entry(bookRecord).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("SportId,SportName,Description")] Sport sport)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sport);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sport));
        }
        public async Task <IActionResult> Create([Bind("PlayerId,FullName,Age,Contry,SportId")] Players players)
        {
            if (ModelState.IsValid)
            {
                _context.Add(players);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(players));
        }
        public async Task <IHttpActionResult> PutSiteBookStatus(Guid id, SiteBookStatus siteBookStatus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != siteBookStatus.Id)
            {
                return(BadRequest());
            }

            using (SportsContext db = new SportsContext())
            {
                db.Entry(siteBookStatus).State = EntityState.Modified;

                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (db.SiteBookStatus.Count(e => e.Id == id) <= 0)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
示例#7
0
        public async Task <IHttpActionResult> PostSite(Site site)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (SportsContext db = new SportsContext())
            {
                db.Sites.Add(site);
                await db.SaveChangesAsync();

                return(CreatedAtRoute("DefaultApi", new { id = site.SiteId }, site));
            }
        }
        public async Task <IHttpActionResult> PostSportsCenter(SportsCenter sportsCenter)
        {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges <SportsContext>());
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (SportsContext db = new SportsContext())
            {
                db.SportsCenters.Add(sportsCenter);
                int effetiveRow = await db.SaveChangesAsync();
            }

            return(CreatedAtRoute("DefaultApi", new { id = sportsCenter.CenterId }, sportsCenter));
        }
示例#9
0
        public async Task UpdateAddress(Person person, Address address)
        {
            if (person.AddressId != null)
            {
                address.AddressId = (int)person.AddressId;
                _context.Addresses.Update(address);
            }
            else
            {
                person.Address = address;
                _context.Add(address);
                _context.Update(person);
            }

            await _context.SaveChangesAsync();
        }
        public async Task <IHttpActionResult> DeleteSiteBookStatus(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                SiteBookStatus siteBookStatus = await db.SiteBookStatus.FindAsync(id);

                if (siteBookStatus == null)
                {
                    return(NotFound());
                }

                db.SiteBookStatus.Remove(siteBookStatus);
                await db.SaveChangesAsync();

                return(Ok(siteBookStatus));
            }
        }
示例#11
0
        public async Task <IHttpActionResult> Delete(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                SportsCenter sportsCenter = await db.SportsCenters.FindAsync(id);

                if (sportsCenter == null)
                {
                    return(NotFound());
                }

                db.SportsCenters.Remove(sportsCenter);
                await db.SaveChangesAsync();

                return(Ok(sportsCenter));
            }
        }
        public async Task <IHttpActionResult> DeleteBookSiteTemplete(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                BookSiteTemplete bookSiteTemplete = await db.BookSiteTempletes.FindAsync(id);

                if (bookSiteTemplete == null)
                {
                    return(NotFound());
                }

                db.BookSiteTempletes.Remove(bookSiteTemplete);
                await db.SaveChangesAsync();

                return(Ok(bookSiteTemplete));
            }
        }
示例#13
0
        public async Task <int> Save()
        {
            try
            {
                var result = await _context.SaveChangesAsync();

                if (result < 1)
                {
                    throw new BusinessException(string.Empty, "There were some problems saving changes to the database");
                }
                return(result);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                throw new BusinessException(string.Empty, "Database problems, couldn't save changes.\n" + ex.ToString());
            }
            catch (DbUpdateException ex)
            {
                throw new BusinessException(string.Empty, "Concurrency problems, couldn't save change.\n" + ex.ToString());
            }
        }