Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ManID,MiddleName,FirstName,LastName,Age,Birthday,NationalityID,Height,Weight,Adress,PhoneNumber,Photo,IsDeleted,PersonalPositionID")] Mans mans)
        {
            if (string.IsNullOrEmpty(mans.MiddleName) || string.IsNullOrEmpty(mans.FirstName))
            {
                failure          = true;
                ViewBag.Failure  = failure;
                ViewBag.FMessage = "Не удалось добавить работника";
                return(RedirectToAction("Index"));
            }
            if (mans.Birthday != null)
            {
                mans.Age = (short?)(DateTime.Now.Year - mans.Birthday.Value.Year);
            }
            if (ModelState.IsValid)
            {
                try
                {
                    db.Mans.Add(mans);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Logger.WriteLog("Ошибка при добавлении пользователя в бд", ex.Message);
                }
                Logger.WriteLog("Работник успешно добавлен ID " + mans.ManID);
                return(RedirectToAction("Index"));
            }

            ViewBag.NationalityID      = new SelectList(db.Nationalities, "NationalityID", "Nationality", mans.NationalityID);
            ViewBag.PersonalPositionID = new SelectList(db.PersosnalPosition.Where(x => new[] { 5, 6, 7, 9, 14 }.Contains(x.PersonalPositionID)), "PersonalPositionID", "Description", mans.PersonalPositionID);
            return(View(mans));
        }
Exemplo n.º 2
0
        // GET: Mans/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mans mans = db.Mans.Find(id);

            try
            {
                mans.IsDeleted = true;
                db.SaveChanges();
                Logger.WriteLog("Удаление прошло успешно: ID ", mans.ManID.ToString());
            }
            catch (Exception ex)
            {
                FMessage = Logger.WriteLog("Ошибка при удалении", ex.Message);
                failure  = true;
                return(View("Index"));
            }
            ViewBag.Players       = db.PlayerInfo;
            ViewBag.Nationalities = db.Nationalities.ToList();
            ViewBag.Mans          = db.Mans.Where(x => x.IsDeleted != true).ToList();
            ViewBag.Failure       = failure;
            ViewBag.FMessage      = FMessage;
            failure = false;
            if (mans == null)
            {
                return(HttpNotFound());
            }
            return(View("Index"));
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Mans mans = db.Mans.Find(id);

            db.Mans.Remove(mans);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 public ActionResult Index(string SearchTerm, string StartAge, string EndAge, string Nationality)
 {
     try
     {
         ViewBag.Players       = db.PlayerInfo;
         ViewBag.Nationalities = db.Nationalities.ToList();
         Mans             = db.Mans.ToList();
         ViewBag.Failure  = failure;
         ViewBag.FMessage = FMessage;
         failure          = false;
         if (!string.IsNullOrEmpty(SearchTerm))
         {
             //x => x.FirstName.ToLower().StartsWith(SearchTerm) || || x.LastName.ToLower().StartsWith(SearchTerm)
             List <Mans> persons = new List <MVCApp.Mans>();
             foreach (var man in Mans)
             {
                 try
                 {
                     if (man.MiddleName.ToLower().Contains(SearchTerm))
                     {
                         persons.Add(man);
                     }
                     else if (man.FirstName.ToLower().Contains(SearchTerm))
                     {
                         persons.Add(man);
                     }
                     else if (man.LastName.ToLower().Contains(SearchTerm))
                     {
                         persons.Add(man);
                     }
                 }
                 catch
                 {
                 }
             }
             Mans = persons;
         }
         if (!string.IsNullOrEmpty(StartAge))
         {
             Mans = Mans.Where(x => x.Age > int.Parse(StartAge)).ToList();
         }
         if (!string.IsNullOrEmpty(EndAge))
         {
             Mans = Mans.Where(x => x.Age < int.Parse(EndAge)).ToList();
         }
         if (!string.IsNullOrEmpty(Nationality))
         {
             Mans = Mans.Where(x => x.NationalityID == int.Parse(Nationality)).ToList();
         }
         ViewBag.Mans = Mans;
         return(View("Index"));
     }
     catch (Exception ex)
     {
         FMessage = Logger.WriteLog("Произошла ошибка при поиске ", ex.Message);
         return(View("Index"));
     }
 }
Exemplo n.º 5
0
 public PartialViewResult OnlyWorking()
 {
     try
     {
         Mans = Mans.Where(x => x.IsDeleted != true).ToList();
         return(PartialView("All", Mans));
     }
     catch (Exception ex)
     {
         FMessage = Logger.WriteLog("Ошибка при загрузке ", ex.Message);
         return(PartialView());
     }
 }
Exemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "ManID,MiddleName,FirstName,LastName,Age,Birthday,NationalityID,Height,Weight,Adress,PhoneNumber,Photo,IsDeleted,PersonalPositionID")] Mans mans)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mans).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             Logger.WriteLog("Ошибка при редактировании пользователя в бд", ex.Message);
         }
         Logger.WriteLog("Пользователь успешно отредактирован в бд ID " + mans.ManID);
         return(RedirectToAction("Index"));
     }
     ViewBag.NationalityID      = new SelectList(db.Nationalities, "NationalityID", "Nationality", mans.NationalityID);
     ViewBag.PersonalPositionID = new SelectList(db.PersosnalPosition, "PersonalPositionID", "Description", mans.PersonalPositionID);
     return(View(mans));
 }
Exemplo n.º 7
0
        // GET: Mans/Edit/5
        public ActionResult Edit(int?id)
        {
            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                Mans mans = db.Mans.Find(id);
                if (mans == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.NationalityID      = new SelectList(db.Nationalities, "NationalityID", "Nationality", mans.NationalityID);
                ViewBag.PersonalPositionID = new SelectList(db.PersosnalPosition, "PersonalPositionID", "Description", mans.PersonalPositionID);
                return(View(mans));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Conflict, ex.Message));
            }
        }
Exemplo n.º 8
0
        // GET: Mans/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                if (db.Players.Where(x => x.ManID == id).Count() > 0)
                {
                    var player = db.Players.Where(x => x.ManID == id).FirstOrDefault();
                    //var stat = db.GetPlayerStat(id);
                    var statistics = db.GetPlayerStatistics(player.PlayerID);
                    //foreach(var s in statistics)
                    //{
                    //    s.Go
                    //}
                    ViewBag.PlayerStat = statistics;
                    ViewBag.LastMatch  = db.PlayerSquad.Where(x => x.PlayerID == player.PlayerID);
                    //Statistics stat = new Statistics();
                    //ViewBag.PlayerStat=db.GetPlayerStatistics(id,out stat.Goals, out stat.Assists, out stat.TimeOnField, out stat.YellowCards, out stat.RedCards)
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog("Не удалось получить статистику по игроку", ex.Message);
            }
            Mans mans = db.Mans.Find(id);

            ViewBag.mans = mans;
            if (mans == null)
            {
                return(HttpNotFound());
            }
            return(View(ViewBag));
        }
Exemplo n.º 9
0
        public ActionResult AddAgent(string Name, string Nationality, DateTime Birthday)
        {
            Mans      man      = new Mans();
            Agents    agent    = new Agents();
            Contracts contract = new Contracts();

            try
            {
                man.NationalityID      = int.Parse(Nationality);
                man.Birthday           = Birthday;
                man.Age                = (short?)(DateTime.Now.Year - Birthday.Year);
                man.LastName           = string.Empty;
                man.PersonalPositionID = 15;
                var playername = Name.Split(' ');
                if (playername.Length == 0)
                {
                    throw new Exception("Имя не определено");
                }
                for (int i = 0; i < playername.Length; i++)
                {
                    switch (i)
                    {
                    case 0:
                        man.MiddleName = playername[i];
                        break;

                    case 1:
                        man.FirstName = playername[i];
                        break;

                    default:
                        man.LastName += playername[i] + " ";
                        break;
                    }
                }
                db.Mans.Add(man);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока", ex.Message);
                try
                {
                    db.Mans.Remove(man);
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            try
            {
                agent.ManID = man.ManID;
                db.Agents.Add(agent);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока", ex.Message);
                db.Mans.Remove(man);
                try
                {
                    db.SaveChanges();
                    db.Agents.Remove(agent);
                    db.SaveChanges();
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            Logger.WriteLog("Игрок успешно добавлен в базу данных: " + man.MiddleName + " ID Agents: " + agent.AgentID + " ID профиля: " + man.ManID + " ID контракта: " + contract.ContractID);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 10
0
        public ActionResult AddPlayerActionResult(string PlayerName, string ShirtName, string Nationality, short?PlayerNumber, DateTime Birthday, DateTime ContractStart, DateTime ContractEnd, double ContractMoney, double TransferPrice, short?Height, short?Weight)
        {
            Mans      man      = new Mans();
            Players   player   = new Players();
            Contracts contract = new Contracts();

            try
            {
                man.NationalityID = int.Parse(Nationality);
                man.Birthday      = Birthday;
                man.Age           = (short?)(DateTime.Now.Year - Birthday.Year);
                man.LastName      = string.Empty;
                man.Height        = Height;
                man.Weight        = Weight;
                if (string.IsNullOrEmpty(PlayerName))
                {
                    throw new Exception("Имя не определено");
                }
                var playername = PlayerName.Split(' ');
                if (playername.Length == 0)
                {
                    throw new Exception("Имя не определено");
                }
                for (int i = 0; i < playername.Length; i++)
                {
                    switch (i)
                    {
                    case 0:
                        man.MiddleName = playername[i];
                        break;

                    case 1:
                        man.FirstName = playername[i];
                        break;

                    default:
                        man.LastName += playername[i] + " ";
                        break;
                    }
                }
                man.PersonalPositionID = 1;
                db.Mans.Add(man);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока", ex.Message);
                try
                {
                    db.Mans.Remove(man);
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            try
            {
                player.ManID = man.ManID;
                if (db.Players.Where(x => x.PlayerNumber == PlayerNumber).Count() > 0)
                {
                    throw new Exception("Игрок с таким номером уже существует");
                }
                player.PlayerNumber = PlayerNumber;
                player.TransferCost = (decimal?)TransferPrice;
                player.ShirtName    = ShirtName;
                if (db.Players.Where(x => x.ShirtName == ShirtName).Count() > 0)
                {
                    throw new Exception("Игрок с таким именем уже существует");
                }
                db.Players.Add(player);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока: " + ex.Message, ex.Message);
                db.Mans.Remove(man);
                try
                {
                    db.SaveChanges();
                    db.Players.Remove(player);
                    db.SaveChanges();
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            try
            {
                contract.PlayerID       = player.PlayerID;
                contract.ContractTypeID = 1;
                contract.StartDate      = ContractStart;
                contract.ExpireDate     = ContractEnd;
                contract.Money          = (decimal?)ContractMoney;
                contract.Tax            = (decimal?)ContractMoney / 100 * 13;
                contract.PlayerID       = player.PlayerID;
                db.Contracts.Add(contract);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока", ex.Message);
                try
                {
                    db.Mans.Remove(man);
                    db.SaveChanges();
                    db.Players.Remove(player);
                    db.SaveChanges();
                    db.Contracts.Remove(contract);
                    db.SaveChanges();
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            Logger.WriteLog("Игрок успешно добавлен в базу данных: " + man.MiddleName + " ID игрока: " + player.PlayerID + " ID профиля: " + man.ManID + " ID контракта: " + contract.ContractID);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public ActionResult AddCoach(string Name, string Nationality, string Position, DateTime Birthday, DateTime ContractEnd, double ContractMoney)
        {
            Mans      man      = new Mans();
            Coachs    coach    = new Coachs();
            Contracts contract = new Contracts();

            try
            {
                man.NationalityID      = int.Parse(Nationality);
                man.Birthday           = Birthday;
                man.Age                = (short?)(DateTime.Now.Year - Birthday.Year);
                man.LastName           = string.Empty;
                man.PersonalPositionID = int.Parse(Position);
                var playername = Name.Split(' ');
                if (playername.Length == 0)
                {
                    throw new Exception("Имя не определено");
                }
                for (int i = 0; i < playername.Length; i++)
                {
                    switch (i)
                    {
                    case 0:
                        man.MiddleName = playername[i];
                        break;

                    case 1:
                        man.FirstName = playername[i];
                        break;

                    default:
                        man.LastName += playername[i] + " ";
                        break;
                    }
                }
                db.Mans.Add(man);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока", ex.Message);
                try
                {
                    db.Mans.Remove(man);
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            try
            {
                coach.ManID = man.ManID;
                db.Coachs.Add(coach);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока", ex.Message);
                db.Mans.Remove(man);
                try
                {
                    db.SaveChanges();
                    db.Coachs.Remove(coach);
                    db.SaveChanges();
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            try
            {
                contract.CoachID        = coach.CoachID;
                contract.ContractTypeID = 1;
                contract.StartDate      = DateTime.Now;
                contract.ExpireDate     = ContractEnd;
                contract.Money          = (decimal?)ContractMoney;
                contract.Tax            = (decimal?)ContractMoney / 100 * 13;
                db.Contracts.Add(contract);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                failure  = true;
                FMessage = Logger.WriteLog("Ошибка при добавлении игрока", ex.Message);
                try
                {
                    db.Mans.Remove(man);
                    db.SaveChanges();
                    db.Coachs.Remove(coach);
                    db.SaveChanges();
                    db.Contracts.Remove(contract);
                    db.SaveChanges();
                }
                catch { }
                return(RedirectToAction("Index"));
            }
            Logger.WriteLog("Игрок успешно добавлен в базу данных: " + man.MiddleName + " ID игрока: " + coach.CoachID + " ID профиля: " + man.ManID + " ID контракта: " + contract.ContractID);
            return(RedirectToAction("Index"));
        }