public ChallangeIdModel ChallangePost(ChallangeModel model) { var Challange = new Entities.Challange() { UserId = model.UserId, Name = model.Name, Phone = model.Phone, IsAdmin = true, IsAccepted = true, StartDateTime = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), IsCompleted = false, CompletedDateTime = null, IsWinner = false, Points = 0 }; entities.Challanges.Add(Challange); entities.SaveChanges(); int ChallangeId = Challange.Id; var data = entities.Challanges.Where(x => x.Id == ChallangeId).FirstOrDefault(); if (data != null) { data.ChallangeId = ChallangeId; entities.SaveChanges(); } return(new ChallangeIdModel() { ChallangeId = data.Id }); }
public AddUserModel AddedUserList(ChallangeModel model) { var data = entities.Challanges.Where(x => x.ChallangeId == model.ChallangeId).ToList(); AddUserModel addUser = new AddUserModel(); List <SearchModel> ChallangesListModel = new List <SearchModel>(); foreach (var item in data) { var Challangers = entities.Challanges.Where(x => x.ChallangeId == model.ChallangeId && x.UserId == item.UserId).FirstOrDefault(); var CLD = new SearchModel(); CLD.UserID = item.UserId; CLD.Name = item.Name; CLD.Phone = item.Phone; if (Challangers != null) { CLD.Status = true; } else { CLD.Status = false; } ChallangesListModel.Add(CLD); } GeneralFunctions general = new GeneralFunctions(); EaningHeadModel eaningHead = new EaningHeadModel(); eaningHead = general.getEarningHeads(); addUser.AddUsers = ChallangesListModel; addUser.MinimumChallangerUsers = eaningHead.MinimumChallangerUsers; return(addUser); }
public bool SaveMinimumEntryPoints(ChallangeModel model) { bool res = false; var data = entities.Challanges.Where(x => x.UserId == model.UserId && x.ChallangeId == model.ChallangeId && x.IsAdmin == true).OrderByDescending(x => x.StartDateTime).FirstOrDefault(); if (data != null) { data.MinimumEntryPoints = model.Points; entities.SaveChanges(); res = true; } return(res); }
public bool AddInvestPoint(ChallangeModel model) { var res = false; var User = entities.Users.Where(x => x.UserID == model.UserId).FirstOrDefault(); if (User.CurrentPoint >= model.Points && User.CurrentPoint > 0) { var data = entities.Challanges.Where(x => x.UserId == model.UserId && x.ChallangeId == model.ChallangeId).OrderByDescending(x => x.StartDateTime).FirstOrDefault(); if (data != null) { data.Points = model.Points; entities.SaveChanges(); res = true; } } return(res); }
public bool ChallengeReject(ChallangeModel model) { var data = entities.Challanges.Where(x => x.UserId == model.UserId && x.ChallangeId == model.ChallangeId).FirstOrDefault(); var Admin = entities.Challanges.Where(x => x.ChallangeId == model.ChallangeId && x.IsAdmin == true).FirstOrDefault(); if (data != null) { data.IsRejected = model.IsRejected; data.IsAccepted = false; //data.ChallangeStartDateTime = Admin.ChallangeStartDateTime; return(entities.SaveChanges() > 0); } else { return(false); } }
public bool SetChallangeResult(ChallangeModel model) { var data = entities.Challanges.Where(x => x.ChallangeId == model.ChallangeId && x.IsAccepted == true).ToList(); var WinUser = data.Where(x => x.UserId == model.UserId && x.ChallangeId == model.ChallangeId).FirstOrDefault(); int Points = 0; foreach (var item in data) { item.IsCompleted = true; item.CompletedDateTime = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00); item.IsWinner = false; Points = Convert.ToInt32(Points + item.Points); UserPoint PointWithdrawal = new UserPoint() { UserID = item.UserId, TransactionDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), PointsWithdraw = item.Points, PointsEarned = 0, Description = "Point Withdrawal for ChallangeId= " + model.ChallangeId, CreatedDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00) }; entities.UserPoints.Add(PointWithdrawal); entities.SaveChanges(); } WinUser.IsCompleted = true; WinUser.CompletedDateTime = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00); WinUser.IsWinner = true; WinUser.Points = Points; UserPoint Point = new UserPoint() { UserID = model.UserId, TransactionDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), PointsWithdraw = 0, PointsEarned = Points, Description = "Point Earn for Win ChallangeId= " + model.ChallangeId, CreatedDate = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00) }; entities.UserPoints.Add(Point); entities.SaveChanges(); return(true); }
public bool AddUserChallange(ChallangeModel model) { var data = new Challange() { UserId = model.UserId, Name = model.Name, Phone = model.Phone, ChallangeId = model.ChallangeId, IsAdmin = false, StartDateTime = DateTime.UtcNow.AddHours(5.00).AddMinutes(30.00), IsCompleted = false, CompletedDateTime = null, IsWinner = false, Points = 0 }; entities.Challanges.Add(data); return(entities.SaveChanges() > 0); }