bool ICodeDaySvc.DeletePlayer(string imei, string deleteCodesFlag) { bool isSuccessful = true; try { using (codeDayEntities context = new codeDayEntities()) { // Delete all users matching the IMEI IList<CD_Users> users = new List<CD_Users>(); users = context.CD_Users.Where(u => u.IMEI == imei).ToList(); foreach (CD_Users user in users) { context.DeleteObject(user); } // Depending on the flag bool isDeleteCodes = Convert.ToBoolean(deleteCodesFlag); if (isDeleteCodes) { IList<CD_Codes> codes = new List<CD_Codes>(); codes = context.CD_Codes.Where(c => c.IMEI == imei).ToList(); foreach (CD_Codes code in codes) { context.DeleteObject(code); } } // Save database all changes context.SaveChanges(); } } catch { isSuccessful = false; } return isSuccessful; }
bool ICodeDaySvc.Scan(string imei, string code, string points) { bool isSuccessful = true; try { using (codeDayEntities context = new codeDayEntities()) { //Make sure the user already exists if (context.CD_Users.Where(u => u.IMEI == imei).Count() > 0) { if (context.CD_Codes.Where(c => c.Code == code).Count() == 0) { context.CD_Codes.AddObject(new CD_Codes { CodeID = Guid.NewGuid(), Code = code, Points = Int32.Parse(points), IMEI = imei, ScanTime = DateTime.Now }); context.SaveChanges(); } else { isSuccessful = false; } } else { isSuccessful = false; } } } catch { isSuccessful = false; } return isSuccessful; }
bool ICodeDaySvc.SetupPlayer(string imei, string nickname) { bool isSuccessful = true; try { using (codeDayEntities context = new codeDayEntities()) { if (context.CD_Users.Where(u => u.IMEI == imei).Count() == 0) { context.CD_Users.AddObject(new CD_Users { IMEI = imei, Nickname = nickname }); } else { CD_Users user = context.CD_Users.Where(u => u.IMEI == imei).FirstOrDefault(); user.Nickname = nickname; } context.SaveChanges(); } } catch { isSuccessful = false; } return isSuccessful; }