public bool CreateOrUpdate(TeamSettingModel model) { var teamSetting = db.TeamSettings.Find(model.TeamId); if (teamSetting == null) { teamSetting = new Data.Models.TeamSetting { ThirdMessage = model.ThirdMessage, SecondaryScreenEndTime = DateTime.Now.AddMinutes(model.SecondaryScreenTime), SecondaryScreenId = model.SecondaryScreenId, PrimaryScreenId = 9, DisplayMode = model.DisplayMode, AutoScreenStartTime = DateTime.Now, TeamId = model.TeamId }; db.TeamSettings.Add(teamSetting); } else { teamSetting.DisplayMode = model.DisplayMode; teamSetting.PrimaryScreenId = model.PrimaryScreenId; teamSetting.SecondaryScreenEndTime = DateTime.Now.AddMinutes(model.SecondaryScreenTime); teamSetting.SecondaryScreenId = model.SecondaryScreenId; teamSetting.ThirdMessage = model.ThirdMessage; teamSetting.FourthMessage = model.FourthMessage; teamSetting.FifthMessage = model.FifthMessage; teamSetting.SixthMessage = model.SixthMessage; teamSetting.SeventhMessage = model.SeventhMessage; teamSetting.EighthMessage = model.EighthMessage; teamSetting.ThirdColor = model.ThirdColor; teamSetting.FourthColor = model.FourthColor; teamSetting.FifthColor = model.FifthColor; teamSetting.SixthColor = model.SixthColor; teamSetting.SeventhColor = model.SeventhColor; teamSetting.EighthColor = model.EighthColor; if (teamSetting.DisplayMode == 1) //auto mode { teamSetting.AutoScreenStartTime = DateTime.Now; teamSetting.FirstScreenTime = model.FirstScreenTime; teamSetting.SecondScreenTime = model.SecondScreenTime; teamSetting.FourthScreenTime = model.FourthScreenTime; teamSetting.FifthScreenTime = model.FifthScreenTime; teamSetting.SixthScreenTime = model.SixthScreenTime; teamSetting.SeventhScreenTime = model.SeventhScreenTime; teamSetting.EighthScreenTime = model.EighthScreenTime; teamSetting.NinthScreenTime = model.NinthScreenTime; } } db.SaveChanges(); return(true); }
public TeamSettingModel AdminGet(int teamId) { var teamSetting = db.TeamSettings.Find(teamId); if (teamSetting == null) { teamSetting = new Data.Models.TeamSetting { ThirdMessage = "Cảm ơn các bạn đã cố gắng!!!", SecondaryScreenEndTime = DateTime.Now.Date, PrimaryScreenId = 9, DisplayMode = 0, TeamId = teamId, DefaultDownMessage = "", DefaultUpMessage = "" }; db.TeamSettings.Add(teamSetting); db.SaveChanges(); } var mapper = config.CreateMapper(); return(mapper.Map <TeamSettingModel>(teamSetting)); }