Пример #1
0
        public async Task <IHttpActionResult> PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> listAddtrainee([Bind("FullName,DateOfBirth,Gender,PhoneNumber,Email,Account,Status,Skill,ForeignLanguage,Level,AllocationStatus")] Trainee trainee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trainee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(trainee));
        }
        public async Task <IActionResult> Create([Bind("ClassAdminId,FullName,DateOfBirth,Gender,PhoneNumber,Email,Account,Status,AuditTrail,isDelete")] ClassAdmin classAdmin)
        {
            if (ModelState.IsValid)
            {
                _context.Add(classAdmin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(classAdmin));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("TrainerId,FullName,DateOfBirth,Gender,PhoneNumber,Email,Account,Status,Type,Unit,Major,Experience,Remarks,AuditTrail,isDelete")] Trainer trainer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trainer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(trainer));
        }
        public async Task <IActionResult> Create([Bind("TraineeId,DateOfBirth,Gender,PhoneNumber,FamilyPhoneNumber,Email,ExternalEmail,Account,OnboardDate,Status,Remarks,University,Faculty,Skill,ForeignLanguage,Level,CV,AllocationStatus,AuditTrail,isDelete,ClassBatchId")] Trainee trainee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trainee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClassBatchId"] = new SelectList(_context.ClassBatches, "ClassId", "AuditTrail", trainee.ClassBatchId);
            return(View(trainee));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("RequestId,RequestType,Reason,StartDate,EndDate,ComimmingTime,LeavingTime,ExpectedApproval,ApprovedTime,Status,AuditTrail,isDelete,TraineeId,ApproverId")] Request request)
        {
            if (ModelState.IsValid)
            {
                _context.Add(request);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TraineeId"] = new SelectList(_context.Trainees, "TraineeId", "Account", request.TraineeId);
            return(View(request));
        }
Пример #7
0
        public async Task <IActionResult> PutTeam([FromForm] TeamsAddModel model)
        {
            Team team = new Team();

            team.Id          = int.Parse(model.Id);
            team.Name        = model.Name;
            team.City        = model.City;
            team.FoundedYear = int.Parse(model.FoundedYear);
            team.Manager     = model.Manager;
            team.Trophies    = int.Parse(model.Trophies);
            team.Owner       = model.Owner;
            team.Budget      = model.Budget;
            team.LeagueId    = int.Parse(model.LeagueId);
            team.StadiumId   = int.Parse(model.StadiumId);
            if (model.Logo != null)
            {
                var filePath = Path.Combine(_env.WebRootPath, "Upload", "Teams");;

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                var fullPath = Path.Combine(_env.WebRootPath, "Upload", "Teams", model.Logo.FileName);
                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    model.Logo.CopyTo(stream);
                }

                team.Logo = "https://localhost:5001/Upload/Leagues/" + model.Logo.FileName;
            }

            if (!TeamExists(team.Id))
            {
                return(NotFound());
            }
            else
            {
                _context.Teams.Update(team);
                await _context.SaveChangesAsync();
            }
            return(Ok());
        }
Пример #8
0
        public async Task <IActionResult> PutPlayer([FromForm] PlayersAddModel model)
        {
            Player player = new Player();

            player.Id        = int.Parse(model.Id);
            player.FirstName = model.FirstName;
            player.LastName  = model.LastName;
            player.Age       = int.Parse(model.Age);
            player.PlayerNo  = model.PlayerNo;
            player.Position  = model.Position;
            player.Kit       = model.Kit;
            player.Price     = decimal.Parse(model.Price);
            player.TeamId    = int.Parse(model.TeamId);
            if (model.Photo != null)
            {
                var filePath = Path.Combine(_env.WebRootPath, "Upload", "Players");

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                var fullPath = Path.Combine(_env.WebRootPath, "Upload", "Players", model.Photo.FileName);
                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    model.Photo.CopyTo(stream);
                }

                player.Photo = "https://localhost:5001/Upload/Players/" + model.Photo.FileName;
            }

            if (!PlayerExists(player.Id))
            {
                return(NotFound());
            }
            else
            {
                _context.Players.Update(player);
                await _context.SaveChangesAsync();
            }
            return(Ok());
        }
Пример #9
0
        public async Task <IActionResult> PutLeague([FromForm] LeaguesAddModel model)
        {
            League league = new League();

            league.Id              = int.Parse(model.Id);
            league.Name            = model.Name;
            league.Country         = model.Country;
            league.FoundedYear     = int.Parse(model.FoundedYear);
            league.MaxNrTeam       = int.Parse(model.MaxNrTeam);
            league.TvPartner       = model.TvPartner;
            league.CurrentChampion = model.CurrentChampion;
            if (model.Logo != null)
            {
                var filePath = Path.Combine(_env.WebRootPath, "Upload", "Leagues");;

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                var fullPath = Path.Combine(_env.WebRootPath, "Upload", "Leagues", model.Logo.FileName);
                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    model.Logo.CopyTo(stream);
                }

                league.Logo = "https://localhost:5001/Upload/Leagues/" + model.Logo.FileName;
            }

            if (!LeagueExists(league.Id))
            {
                return(NotFound());
            }
            else
            {
                _context.Leagues.Update(league);
                await _context.SaveChangesAsync();
            }
            return(Ok());
        }
Пример #10
0
        public async Task <IActionResult> PutStadium([FromForm] StadiumsAddModel model)
        {
            Stadium stadium = new Stadium();

            stadium.Id       = int.Parse(model.Id);
            stadium.Name     = model.Name;
            stadium.Capacity = int.Parse(model.Capacity);
            stadium.Rank     = int.Parse(model.Rank);
            if (model.Image != null)
            {
                var filePath = Path.Combine(_env.WebRootPath, "Upload", "Stadiums");;

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                var fullPath = Path.Combine(_env.WebRootPath, "Upload", "Stadiums", model.Image.FileName);
                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    model.Image.CopyTo(stream);
                }

                stadium.Image = "https://localhost:5001/Upload/Stadiums/" + model.Image.FileName;
            }

            if (!StadiumExists(stadium.Id))
            {
                return(NotFound());
            }
            else
            {
                _context.Stadiums.Update(stadium);
                await _context.SaveChangesAsync();
            }
            return(Ok());
        }
 public async Task <int> CreateAsync(TEntity entity)
 {
     _dbSet.Add(entity);
     return(await _context.SaveChangesAsync());
 }