/// <summary> /// Insert one ClubPoint to the database /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Insert(ClubPoint entity) { entity.CreatedDate = entity.ModifiedDate = DateTime.Now; entity.Status = true; db.ClubPoints.Add(entity); db.SaveChanges(); return(true); }
/// <summary> /// Update a ClubPoint row /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Update(ClubPoint entity) { try { var clubPoint = db.ClubPoints.Find(entity.MatchID, entity.ClubID); clubPoint.JoinPoint = entity.JoinPoint; clubPoint.WinPoint = entity.WinPoint; clubPoint.DrawPoint = entity.DrawPoint; clubPoint.GoalPoint = entity.GoalPoint; clubPoint.RivalLevelID = entity.RivalLevelID; clubPoint.ModifiedDate = DateTime.Now; clubPoint.Status = entity.Status; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public ActionResult Result(MatchViewModel matchViewModel) { Match match = new Match(); if (ModelState.IsValid) { //Update kết quả của Match match.ID = matchViewModel.ID; match.Code = matchViewModel.Code; match.Name = matchViewModel.Name; match.Description = matchViewModel.Description; match.Image = matchViewModel.Image; match.HomeClubID = matchViewModel.HomeClubID; match.VisitingClubID = matchViewModel.VisitingClubID; match.StadiumID = matchViewModel.StadiumID; match.Date = matchViewModel.Date; match.ExpectedStartTime = matchViewModel.ExpectedStartTime; match.ExpectedEndTime = matchViewModel.ExpectedEndTime; match.HoldAddress = matchViewModel.HoldAddress; match.Price = matchViewModel.Price; match.PromotionPrice = matchViewModel.PromotionPrice; match.ExpiredDateToSign = matchViewModel.ExpiredDateToSign; match.Detail = matchViewModel.Detail; match.RealStartTime = matchViewModel.RealStartTime; match.RealEndTime = matchViewModel.RealEndTime; match.HomeClubGoal = matchViewModel.HomeClubGoal; match.VisitingClubGoal = matchViewModel.VisitingClubGoal; match.Status = matchViewModel.Status; match.MetaKeywords = matchViewModel.MetaKeywords; match.MetaDescriptions = matchViewModel.MetaDescriptions; if (!string.IsNullOrEmpty(match.Name)) { match.MetaTitle = StringHelper.ToUnsignString(match.Name); } var result = new MatchDao().Update(match); if (result) { SetAlert("Result this match successfully.", "success"); } else { ModelState.AddModelError("", "Result this match failed."); } //Update ClubPoint cho cả hai đội ClubPoint homePoint = new ClubPoint(); homePoint.MatchID = match.ID; homePoint.ClubID = (long)match.HomeClubID; homePoint.JoinPoint = CommonConstants.JoinPoint; homePoint.WinPoint = (match.HomeClubGoal > match.VisitingClubGoal == true ? CommonConstants.WinPoint : 0); homePoint.DrawPoint = (match.HomeClubGoal == match.VisitingClubGoal == true ? CommonConstants.DrawPoint : 0); homePoint.Status = true; ClubPoint visitingPoint = new ClubPoint(); visitingPoint.MatchID = match.ID; visitingPoint.ClubID = (long)match.VisitingClubID; visitingPoint.JoinPoint = CommonConstants.JoinPoint; visitingPoint.WinPoint = (match.VisitingClubGoal > match.HomeClubGoal == true ? CommonConstants.WinPoint : 0); visitingPoint.DrawPoint = (match.VisitingClubGoal == match.HomeClubGoal == true ? CommonConstants.DrawPoint : 0); visitingPoint.Status = true; var homeLevel = new ClubLevelDao().GetBeforeDate(homePoint.ClubID, (DateTime)match.Date); var visitingLevel = new ClubLevelDao().GetBeforeDate(visitingPoint.ClubID, (DateTime)match.Date); homePoint.RivalLevelID = visitingLevel.LevelID; visitingPoint.RivalLevelID = homeLevel.LevelID; var dao = new ClubPointDao(); if (dao.CheckExist(homePoint.MatchID, homePoint.ClubID) == true) { dao.Update(homePoint); } else { dao.Insert(homePoint); } if (dao.CheckExist(visitingPoint.MatchID, visitingPoint.ClubID) == true) { dao.Update(visitingPoint); } else { dao.Insert(visitingPoint); } } SetStatusViewBag(matchViewModel.Status); return(View(matchViewModel)); }