public IActionResult AssignFouls(FoulInputVM model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(AssignFouls), new { id = model.MatchId, message = 1 }));
            }
            var fouls    = _dataFoul.GetByDetails();
            var lastFoul = fouls.LastOrDefault(x => x.MatchId == model.MatchId);
            var foul     = new Foul
            {
                Minute   = model.Minute,
                MatchId  = model.MatchId,
                Penalty  = model.Penalty,
                PlayerId = model.PlayerId,
                VictimId = model.VictimId
            };

            if (lastFoul == null && model.Minute >= 1 && model.Minute <= 93)
            {
                _dataFoul.Add(foul);
            }
            else if (lastFoul != null && model.Minute >= 1 && model.Minute <= 93 &&
                     model.Minute > lastFoul.Minute)
            {
                _dataFoul.Add(foul);
            }
            else
            {
                return(RedirectToAction(nameof(AssignFouls), new { id = model.MatchId, leagueId = model.LeagueId, message = 1 }));
            }

            return(RedirectToAction(nameof(Index), new { id = model.LeagueId }));
        }
Пример #2
0
        public async Task <ActionResult <EmployeesDto> > Post(EmployeeCreation employee)
        {
            var person = mapper.Map <Entities.Employee>(employee);
            await data.Add(person);

            await data.Save();

            var link        = CreateEmployeeLink(person.EmployeeId, null);
            var newemployee = mapper.Map <EmployeesDto>(person).ShapeData(null) as IDictionary <string, object>;

            newemployee.Add("links", link);
            return(Created("Created", newemployee));
        }
Пример #3
0
        public IActionResult Save(Player player)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <SelectListItem> citiesList = _dataCity.GetByDetails().Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                });

                var list = Globals.ToPairList <StrongerFoot>(typeof(StrongerFoot));

                PlayerInputVM viewModel = new PlayerInputVM();
                viewModel.Cities        = citiesList.ToList();
                viewModel.StrongerFoots = list.Select(x => new SelectListItem(x.Value, x.Key.ToString()));
                var mappedForView = _mapper.Map <Player, PlayerInputVM>(player, viewModel);

                return(View(nameof(Create), mappedForView));
            }

            if (player.Id == 0)
            {
                _dataPlayer.Add(player);
            }
            else
            {
                var playerInDb   = _dataPlayer.Get(player.Id);
                var mappedPlayer = _mapper.Map <Player, Player>(player, playerInDb);
                _dataPlayer.Update(mappedPlayer);
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #4
0
        private void CreateMeeting(User user)
        {
            user.Meeting = new List <Meeting>();
            var medicalCondition = _repositoryMedicalCondition.Get(user.MedicalCondition.Id);

            user.MedicalCondition = medicalCondition;
            var date = DateTime.Now;

            date = ChangeDate(date);
            var          list           = ListOfPsychologist(medicalCondition);
            Meeting      meeting        = new Meeting();
            Psychologist unPsychologist = FreePsychologist(list, date, meeting);

            if (ExistUser(user))
            {
                User newuser = _repositoryUser.Get(UserId(user));
                newuser.MeetingDuration = user.MeetingDuration;
                SetMeeting(newuser, unPsychologist, meeting);
                SetMeetingCount(newuser);
                newuser.Meeting.Add(meeting);
                user.Meeting = newuser.Meeting;
                UpdateByUser(newuser, newuser.Id);
            }
            else
            {
                SetMeeting(user, unPsychologist, meeting);
                SetMeetingCount(user);
                user.Meeting.Add(meeting);
                _repositoryUser.Add(user);
            }
        }
Пример #5
0
        public IActionResult Save(League model)
        {
            if (!ModelState.IsValid)
            {
                var leagueInput = new LeagueInputVM
                {
                    Name        = model.Name,
                    CountryId   = model.CountryId,
                    NameCountry = model.Name
                };
                return(View("Create", leagueInput));
            }

            IEnumerable <League> leagues = _dataLeague.GetByDetails();

            foreach (var item in leagues)
            {
                if (item.Name == model.Name)
                {
                    return(RedirectToAction("Error", "Home"));
                }
            }
            _dataLeague.Add(model);
            return(RedirectToAction(nameof(Index), new { id = model.CountryId }));
        }
Пример #6
0
        public IActionResult OnPost(int recipeId, int?ingredientId)
        {
            if (!ModelState.IsValid)
            {
                if (!LoadData(recipeId, ingredientId))
                {
                    return(RedirectToPage("/Recipes/List"));
                }
                return(Page());
            }

            if (Ingredient.RecipeId < 1)
            {
                Ingredient.RecipeId = recipeId;
                ingredientData.Add(Ingredient);
            }

            ingredientData.Commit();
            CurrentRecipe           = recipeData.GetById(recipeId);
            CurrentRecipe.UpdatedOn = DateTime.Now;
            recipeData.Update(CurrentRecipe);
            recipeData.Commit();

            return(RedirectToPage("/Recipes/Edit", new { id = recipeId }));
        }
Пример #7
0
 public IActionResult Save(Referee referee)
 {
     if (!ModelState.IsValid)
     {
         IEnumerable <SelectListItem> countriesList = _dataCountry.GetByDetails().Select(x => new SelectListItem
         {
             Text  = x.Name,
             Value = x.Id.ToString()
         });
         RefereeInputVM viewmodel = new RefereeInputVM
         {
             Countries  = countriesList.ToList(),
             FirstName  = referee.FirstName,
             MiddleName = referee.MiddleName,
             LastName   = referee.LastName,
             CountryId  = referee.CountryId
         };
         return(View(nameof(Create), viewmodel));
     }
     if (referee.Id == 0)
     {
         _dataReferee.Add(referee);
     }
     else
     {
         var refereeInDB = _dataReferee.Get(referee.Id);
         refereeInDB.Id         = referee.Id;
         refereeInDB.FirstName  = referee.FirstName;
         refereeInDB.MiddleName = referee.MiddleName;
         refereeInDB.LastName   = referee.LastName;
         refereeInDB.CountryId  = referee.CountryId;
         _dataReferee.Update(refereeInDB);
     }
     return(RedirectToAction(nameof(Index)));
 }
Пример #8
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Product product;

            if (ProductViewModel.Id > 0)
            {
                product = productData.GetById(ProductViewModel.Id);
                if (product == null)
                {
                    return(RedirectToPage("./List"));
                }

                product.SetFromViewModel(ProductViewModel);

                productData.Update(product);
            }
            else
            {
                product = new Product();
                product.SetFromViewModel(ProductViewModel);
                productData.Add(product);
            }

            productData.Commit();
            return(RedirectToPage("./List"));
        }
        public IActionResult Save(City model)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <SelectListItem> list = _dataCountry.GetByDetails().Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                });
                var cityInput = new CityInputVM
                {
                    Name       = model.Name,
                    PostalCode = model.PostalCode,
                    CountryId  = model.CountryId,
                    Countries  = list.ToList()
                };
                return(View("Create", cityInput));
            }

            IEnumerable <City> cities = _dataCity.GetByDetails();

            foreach (var item in cities)
            {
                if (item.Name == model.Name)
                {
                    return(RedirectToAction(nameof(Index), "Home"));
                }
            }

            _dataCity.Add(model);
            return(RedirectToAction("Create", "Players"));
        }
Пример #10
0
        public IActionResult Generate(int id)
        {
            var clubs = _dataClub.GetByDetails().Where(x => x.LeagueId == id).ToList();

            foreach (var item in clubs)
            {
                var stadium = _dataStadium.GetByDetails().First(x => x.ClubId == item.Id);
                foreach (var item2 in clubs)
                {
                    if (item.Name != item2.Name)
                    {
                        var match = new Match
                        {
                            HomeClubId = item.Id,
                            AwayClubId = item2.Id,
                            TimePlayed = DateTime.Now,
                            LeagueId   = id,
                            StadiumId  = stadium.Id
                        };
                        _dataMatch.Add(match);
                    }
                }
            }
            return(RedirectToAction(nameof(Index), "Matches"));
        }
        public IActionResult Save(Country model)
        {
            if (!ModelState.IsValid)
            {
                var list = Globals.ToPairList <Confederations>(typeof(Confederations));

                CountryInputVM viewModel = new CountryInputVM
                {
                    Name           = model.Name,
                    Code           = model.Code,
                    Confederations = list.Select(x => new SelectListItem(x.Value, x.Key.ToString()))
                };
                return(View("Create", viewModel));
            }

            List <Country> countries = _dataCountry.GetByDetails().ToList();

            foreach (var item in countries)
            {
                if (item.Name == model.Name)
                {
                    return(RedirectToAction("Error", "Home"));
                }
            }

            _dataCountry.Add(model);
            return(RedirectToAction("Create", "Cities"));
        }
Пример #12
0
        public IActionResult OnPost()
        {
            RecipeIngredients = new List <RecipeIngredientViewModel>();

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (RecipeId > 0)
            {
                Recipe = recipeData.GetById(RecipeId);

                if (Recipe == null)
                {
                    RedirectToPage("./List");
                }

                SetRecipeProperties(Recipe, DateTime.Now);
                recipeData.Update(Recipe);
            }
            else
            {
                Recipe           = new Recipe();
                Recipe.CreatedOn = DateTime.Now;
                Recipe.IsActive  = true;
                SetRecipeProperties(Recipe, Recipe.CreatedOn);
                recipeData.Add(Recipe);
            }

            recipeData.Commit();
            return(RedirectToPage("./Edit", new { id = Recipe.Id }));
        }
Пример #13
0
        public IActionResult OnGet(int id)
        {
            Recipe recipe = recipeData.GetById(id);

            if (recipe == null)
            {
                return(RedirectToPage("./List"));
            }

            Recipe recipeCopy = new Recipe();

            recipeCopy.Name      = recipe.Name + " - Copy";
            recipeCopy.CreatedOn = DateTime.Now;
            recipeCopy.UpdatedOn = DateTime.Now;
            recipeCopy.IsActive  = recipe.IsActive;
            recipeCopy.ResultingQuantityInGrams = recipe.ResultingQuantityInGrams;
            recipeData.Add(recipeCopy);
            recipeData.Commit();

            foreach (Ingredient i in recipe.Ingredients)
            {
                Ingredient newIngredient = new Ingredient();
                newIngredient.Quantity  = i.Quantity;
                newIngredient.RecipeId  = recipeCopy.Id;
                newIngredient.ProductId = i.ProductId;
                ingredientData.Add(newIngredient);
            }
            ingredientData.Commit();

            return(RedirectToPage("./List"));
        }
 public void Add(Administrator administrator)
 {
     ValidateAdministrator(administrator);
     ValidateEmailUnique(administrator.Email);
     administrator.Email = administrator.Email.ToLower();
     administrator.Token = Guid.NewGuid();
     repositoryAdministrator.Add(administrator);
 }
Пример #15
0
 public IActionResult Post(MeasureDTO measure)
 {
     if (measure == null)
     {
         return(BadRequest());
     }
     Measures.Add(DTO.FromDTO(measure));
     return(Ok(measure));
 }
Пример #16
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         data.Add(Books);
         data.Commit();
         return(RedirectToPage("./Addlist", new { id = Books.Id }));
     }
     return(Page());
 }
Пример #17
0
 public override void Handle(UpdateOrAddDeviceCommand command)
 {
     if (!string.IsNullOrEmpty(command.DeviceModel.Id))
     {
         _deviceData.Update(command.DeviceModel.MapToDeviceDataModel());
     }
     else
     {
         _deviceData.Add(command.DeviceModel.MapToDeviceDataModel());
     }
 }
Пример #18
0
        public void Add(Video video)
        {
            ValidateVideo(video);
            if (ExistVideoByName(video) == true)
            {
                throw new EntityAlreadyExist("The video with name: " + video.Name + " already exist");
            }
            Video unVideo = ToEntity(video);

            videoRepository.Add(video);
        }
Пример #19
0
        public void Add(Psychologist psychologist)
        {
            ValidatePsychologist(psychologist);
            if (psychologist.Meeting.Count > 0)
            {
                throw new FieldEnteredNotCorrect("The meeting must be empty");
            }
            Psychologist psy = ToEntity(psychologist);

            _repository.Add(psy);
        }
Пример #20
0
        public void Add(Playlist playlist)
        {
            ValidatePlaylist(playlist);
            if (ExistPlaylistByName(playlist) == true)
            {
                throw new EntityAlreadyExist("The track with name: " + playlist.Name + " already exist");
            }
            Playlist play = ToEntity(playlist);

            _repository.Add(play);
        }
Пример #21
0
        public void Add(Track track)
        {
            ValidateTrack(track);
            if (ExistTrackByName(track) == true)
            {
                throw new EntityAlreadyExist("The track with name: " + track.Name + " already exist");
            }
            Track unTrack = ToEntity(track);

            _repository.Add(unTrack);
        }
Пример #22
0
        public ActionResult Create(WorkItem workitem)
        {
            //Implement the create function

            if (ModelState.IsValid)
            {
                db.Add(workitem);
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Пример #23
0
        public async Task <IActionResult> Post([FromBody] Empleat empleat)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _data.Add(empleat);
            var save = await _data.SaveAsync(empleat);

            return(CreatedAtAction("GetBlogPost", new { id = empleat.Id }, empleat));
        }
Пример #24
0
        public IActionResult AssignContract(ContractInputVM model)
        {
            if (model.SignedDate > model.ExpirationDate)
            {
                return(RedirectToAction(nameof(AssignContract), new { id = model.PlayerId, message = 1 }));
            }
            var playerClubs       = new Contract();
            var mappedForDatabase = _mapper.Map <ContractInputVM, Contract>(model, playerClubs);

            _dataContract.Add(mappedForDatabase);
            return(RedirectToAction(nameof(Index)));
        }
Пример #25
0
 public IActionResult Post(WeighingDTO weighing)
 {
     try
     {
         Weighings.Add(DTO.FromDTO(weighing));
         return(Ok(weighing));
     }
     catch
     {
         return(BadRequest());
     }
 }
        public IActionResult AddGoal(GoalInputVM model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(AssignGoals), new { id = model.MatchId, message = 1 }));
            }
            var goals    = _dataGoal.GetByDetails();
            var lastGoal = goals.LastOrDefault(x => x.MatchId == model.MatchId);
            var goal     = new Goal
            {
                Minute      = model.Minute,
                Time        = model.Time,
                AssistantId = model.AssistantId,
                ScorerId    = model.ScorerId,
                MatchId     = model.MatchId
            };

            if (lastGoal == null &&
                ((model.Minute >= 1 && model.Minute <= 45 && model.Time.ToString() == "First") ||
                 (model.Minute >= 46 && model.Minute <= 93 && model.Time.ToString() == "Second")))
            {
                _dataGoal.Add(goal);
            }
            else if (lastGoal != null && model.Minute > lastGoal.Minute &&
                     model.Minute >= 1 && model.Minute <= 45 && model.Time.ToString() == "First")
            {
                _dataGoal.Add(goal);
            }
            else if (lastGoal != null && model.Minute > lastGoal.Minute &&
                     model.Minute >= 46 && model.Minute <= 93 && model.Time.ToString() == "Second")
            {
                _dataGoal.Add(goal);
            }
            else
            {
                return(RedirectToAction(nameof(AssignGoals), new { id = model.MatchId, leagueId = model.LeagueId, message = 1 }));
            }

            return(RedirectToAction(nameof(Index), new { id = model.LeagueId }));
        }
 public IActionResult AssignClub(CoachClubInputVM model)
 {
     for (var i = 0; i < model.Ids.Count(); i++)
     {
         var coachesClubs = new CoachClub
         {
             CoachId = model.CoachId,
             ClubId  = model.Ids[i]
         };
         _dataCoachClub.Add(coachesClubs);
     }
     return(RedirectToAction(nameof(Index)));
 }
 public IActionResult AssignReferee(RefereeMatchInputVM model)
 {
     for (var i = 0; i < model.Ids.Count(); i++)
     {
         var refereeMatch = new RefereeMatch
         {
             MatchId   = model.MatchId,
             RefereeId = model.Ids[i]
         };
         _dateRefereeMatch.Add(refereeMatch);
     }
     return(RedirectToAction(nameof(Index)));
 }
        public IActionResult AssignCorners(CornerInputVM model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(AssignCorners), new { id = model.MatchId, message = 1 }));
            }
            var corners    = _dataCorner.GetByDetails();
            var lastCorner = corners.LastOrDefault(x => x.MatchId == model.MatchId);
            var corner     = new Corner
            {
                MinuteAwarded = model.MinuteAwarded,
                HalfTime      = model.HalfTime,
                TakerId       = model.TakerId,
                MatchId       = model.MatchId
            };

            if (lastCorner == null &&
                ((model.MinuteAwarded >= 1 && model.MinuteAwarded <= 45 && model.HalfTime.ToString() == "First") ||
                 (model.MinuteAwarded >= 46 && model.MinuteAwarded <= 93 && model.HalfTime.ToString() == "Second")))
            {
                _dataCorner.Add(corner);
            }
            else if (lastCorner != null && model.MinuteAwarded > lastCorner.MinuteAwarded &&
                     model.MinuteAwarded >= 1 && model.MinuteAwarded <= 45 && model.HalfTime.ToString() == "First")
            {
                _dataCorner.Add(corner);
            }
            else if (lastCorner != null && model.MinuteAwarded > lastCorner.MinuteAwarded &&
                     model.MinuteAwarded >= 46 && model.MinuteAwarded <= 93 && model.HalfTime.ToString() == "Second")
            {
                _dataCorner.Add(corner);
            }
            else
            {
                return(RedirectToAction(nameof(AssignCorners), new { id = model.MatchId, leagueId = model.LeagueId, message = 1 }));
            }

            return(RedirectToAction(nameof(Index), new { id = model.LeagueId }));
        }
Пример #30
0
 public IActionResult AssignPosition(PlayerPositionsInputVM model)
 {
     for (var i = 0; i < model.Ids.Count(); i++)
     {
         var playerPosition = new PlayerPosition
         {
             PlayerId   = model.PlayerId,
             PositionId = model.Ids[i]
         };
         _dataPlayerPosition.Add(playerPosition);
     }
     return(RedirectToAction(nameof(Index)));
 }