Ejemplo n.º 1
0
        public ActionResult CreateBet(string jsonModel)
        {
            try
            {
                CreateBetViewModel model = JsonConvert.DeserializeObject <CreateBetViewModel>(jsonModel);
                Bet bet = AutoMapper.Mapper.Map <CreateBetViewModel, Bet>(model);
                bet.StatusId = BetsRepository.GetStatusNumber(BetStatus.Applying);
                bet.Interest = unitOfWork.InterestsRepository.Get(bet.InterestId);
                unitOfWork.BetsRepository.Create(bet);
                bet.Id = unitOfWork.BetsRepository.GetAll().LastOrDefault().Id;
                string curUserId = unitOfWork.UsersRepository.GetAll().Where(u => u.UserName == User.Identity.Name).FirstOrDefault().Id;
                unitOfWork.Save();
                unitOfWork.UsersInBetRepository.CreateForUser(curUserId, bet);
                foreach (var user in model.Users)
                {
                    unitOfWork.UsersInBetRepository.CreateForUser(user.Id, bet);
                }

                ViewBag.SuccesCreateBet = true;
                unitOfWork.Save();
                RedirectToAction("AllBets", "Bet");
            }
            catch (Exception ex)
            {
                throw;
            }
            return(RedirectToAction("AllUsers", "Home"));
        }
Ejemplo n.º 2
0
 public ActionResult Create(CreateBetViewModel model)
 {
     if (ModelState.IsValid)
     {
         Bet bet = AutoMapper.Mapper.Map <Bet>(model);
         bet.StatusId = BetsRepository.GetStatusNumber(BetStatus.Applying);
         unitOfWork.BetsRepository.Create(bet);
         unitOfWork.Save();
         RedirectToAction("Index");
     }
     return(View(model));
 }