public int Update(match_goal entity)
        {
            try
            {
                // check time_at
                var info_rule = new general_rule_dao().GetRule();

                if (entity.time_at > info_rule.max_time_goal)
                {
                    return(-2);
                }

                // for updating
                var info = db.match_goal.Find(entity.id);
                info.time_at       = entity.time_at;
                info.footballer_id = entity.footballer_id;
                info.goal_type_id  = entity.goal_type_id;
                info.match_id      = entity.match_id;
                db.SaveChanges();
                return(1);
            }
            catch (Exception)
            {
                return(-1);
            }
        }
Example #2
0
        public ActionResult Create(match_goal match_goal)
        {
            if (ModelState.IsValid)
            {
                var dao       = new match_goal_dao();
                var info_rule = new general_rule_dao().GetRule();

                var result = dao.Insert(match_goal);
                if (result == 1)
                {
                    SetAlert(StaticResources.Resources.Pub_InsertSuccess, "success");
                    return(RedirectToAction("Index", "MatchGoal", new { match_id = match_goal.match_id }));
                }
                else if (result == -2)
                {
                    ModelState.AddModelError("", "Thởi điểm ghi bàn không hợp lệ (từ 0 -> " + info_rule.max_time_goal + ")");
                }
                else
                {
                    ModelState.AddModelError("", StaticResources.Resources.InsertMatchGoalFailed);
                }
            }
            SetListGoalType(match_goal.goal_type_id);
            SetListFootballer(match_goal.match_id, match_goal.footballer_id);
            ViewBag.CurrentMatchID = match_goal.match_id;
            return(View());
        }
        //common lib

        /// <summary>
        /// return -2 (time_at invalid)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Insert(match_goal entity)
        {
            try
            {
                var info_rule = new general_rule_dao().GetRule();

                if (entity.time_at > info_rule.max_time_goal)
                {
                    return(-2);
                }
                db.match_goal.Add(entity);
                db.SaveChanges();
                return(1);
            }
            catch (Exception)
            {
                return(-1);
            }
        }