public FollowUserReturn UnFollowUser(string unFollowedUsername, string followingId) { FollowUserReturn ret = new FollowUserReturn(); if (string.IsNullOrEmpty(unFollowedUsername) || string.IsNullOrEmpty(followingId)) { ret.LastFollowState = FollowState.Unfollowed; return(ret); } UserInfo uInfo = _context.Set <UserInfo>().AsNoTracking().Include(f => f.Followers).FirstOrDefault(f => f.UName == unFollowedUsername); FollowInfo finf = uInfo.Followers.FirstOrDefault(f => f.FollowerId == followingId && f.FollowedId == uInfo.AppUserId); if (finf == null) { ret.IsActionSucceed = false; ret.ErrorInformation.UserInformation = "You are not following this user"; ret.ErrorInformation.ErrorType = ErrorType.NoAction; ret.LastFollowState = FollowState.Unfollowed; return(ret); } finf.FollowState = FollowState.Unfollowed; ret.LastFollowState = FollowState.Unfollowed; _context.SetChild <FollowInfo>().Update(finf); if (_context.SaveChanges() != 0) { _userFollowCacheService.RemoveAllUserCache(followingId); ret.IsActionSucceed = true; } ; return(ret); }
public List <FollowInfo> GetByUser(FollowInfo followInfo) { var dbRecords = Container.Table_FollowInfo.Where(x => x.UserId.Equals(followInfo.UserId)); List <FollowInfo> result = new List <FollowInfo>(); dbRecords.ToList().ForEach(x => result.Add(FollowInfoMapper.Convert(x))); return(result); }
public IActionResult UnFollowProject([FromBody] FollowInfo model) { var followProject = _db.FollowsUser.ToList().FirstOrDefault(p => (p.ProjectId == model.ProjectId) && (p.UserId == model.UserId)); _db.FollowsUser.Remove(followProject); _db.SaveChanges(); return(Ok()); }
public FollowInfo Update(FollowInfo record) { MYS_FOLLOWINFO updatedRecord = FollowInfoMapper.ConvertToDBRecord(record); var dbRecord = Container.Table_FollowInfo.Attach(updatedRecord); if (Container.SaveChanges() == 1) { record.Id = dbRecord.Id; } return(record); }
public FollowInfo Insert(FollowInfo record) { MYS_FOLLOWINFO newRecord = FollowInfoMapper.ConvertToDBRecord(record); var dbRecord = Container.Table_FollowInfo.Add(newRecord); if (Container.SaveChanges() == 1) { record.Id = dbRecord.Id; } return(record); }
public IActionResult FollowProject([FromBody] FollowInfo model) { var followProject = new FollowsUser { UserId = model.UserId, ProjectId = model.ProjectId }; _db.FollowsUser.Add(followProject); _db.SaveChanges(); return(Ok()); }
public static MYS_FOLLOWINFO ConvertToDBRecord(FollowInfo followInfo) { return(new MYS_FOLLOWINFO { Id = followInfo.Id, UserId = followInfo.UserId, EndDate = followInfo.EndDate, EndTime = followInfo.EndTime, IsActive = followInfo.IsActive, StartDate = followInfo.StartDate, StartTime = followInfo.StartTime, OpponentUserId = followInfo.OpponentUserId }); }
public FollowInfo IsFollowed(string id, string username) { var info = new FollowInfo { Followers = this.db.Followers.Where(f => f.FollowedId == id).Count(), Followed = this.db.Followers.Where(f => f.UserId == id).Count() }; var user = this.db.Users.FirstOrDefault(u => u.UserName == username); if (this.db.Followers.Any(f => f.FollowedId == id && f.UserId == user.Id)) { info.Follow = true; } else { info.Follow = false; } return(info); }
public IActionResult AddProjection(IFormCollection formCollection) { List <FollowInfo> list = new List <FollowInfo>(); Project p = projectmanager.getProjet(Convert.ToInt32(formCollection["id"])); string[] Spending = formCollection["Spending"]; string[] montant = formCollection["Montant"]; string[] color = formCollection["color"]; int count = 0; foreach (var item in p.listProjectSoumission()) { FollowInfo f = new FollowInfo(); f.amount = Convert.ToDouble(montant[count]); f.Spending = Spending[count]; f.color = color[count]; list.Add(f); count++; } ProjectFollowUp projectFollowUp = new ProjectFollowUp(); projectFollowUp.PfFollowUpId = Convert.ToInt32(formCollection["id"]); FollowUp follow = new FollowUp(); follow.FuDate = DateTime.Now; follow.FuInfo = JsonConvert.SerializeObject(list); FollowUp ff = new FollowUp(); ff = _context.FollowUp.Last(); _context.Add(follow); _context.SaveChanges(); projectFollowUp.PfFollowUpId = follow.FuId; projectFollowUp.PfProject = p; projectFollowUp.PfFollowUp = follow; _context.ProjectFollowUp.Add(projectFollowUp); _context.SaveChanges(); return(RedirectToAction("Projet", new { id = formCollection["id"] })); }
public FollowInfo Get(FollowInfo record) { var dbRecord = Container.Table_FollowInfo.Find(record.Id); return(FollowInfoMapper.Convert(dbRecord)); }
public bool Delete(FollowInfo record) { Container.Table_FollowInfo.Remove(Container.Table_FollowInfo.Find(record.Id)); return(Container.SaveChanges() == 1); }
public FollowInfo AddNewFollowInfo(FollowInfo newFollowInfo) { FollowInfoDataAccessManager followInfoDataAccess = new FollowInfoDataAccessManager(); return(followInfoDataAccess.Insert(newFollowInfo)); }
public List <FollowInfo> GetFollowInfoByUser(FollowInfo followInfo) { FollowInfoDataAccessManager followInfoDataAccess = new FollowInfoDataAccessManager(); return(followInfoDataAccess.GetByUser(followInfo)); }
public FollowInfo DeleteFollowInfo(FollowInfo followInfoToDelete) { FollowInfoDataAccessManager followInfoDataAccess = new FollowInfoDataAccessManager(); return(followInfoDataAccess.Update(followInfoToDelete)); }
public IActionResult Addprojet(IFormCollection formCollection) { ProjectFollowUp projectFollowUp = new ProjectFollowUp(); ProjectExpense projectExpense = new ProjectExpense(); Project p = new Project(); p.ProjectName = formCollection["ProjectName"]; p.ProjectDebut = Convert.ToDateTime(formCollection["project_debut"]); p.ProjectFin = Convert.ToDateTime(formCollection["project-fin"]); //TOFIX: La sérialisation JSON Échoue s'il y a plus qu'un mot dans le champ "Spending" //I know on va juste empecher avec des espaces FollowInfo[] follwlist = new JavaScriptSerializer().Deserialize <FollowInfo[]>(formCollection["table"]); List <FollowInfo> soumission = new List <FollowInfo>(); foreach (var item in follwlist) { soumission.Add(item); } FollowUp follow = new FollowUp(); follow.FuDate = DateTime.Now; follow.FuInfo = JsonConvert.SerializeObject(soumission); List <ExpenseInfo> expenseInfo = new List <ExpenseInfo>(); foreach (var item in soumission) { ExpenseInfo expenses = new ExpenseInfo(); List <FollowInfo> subex = new List <FollowInfo>(); FollowInfo ex = new FollowInfo(); expenses.Spending = item.Spending; expenses.amount = 0; ex.Spending = "Title"; ex.amount = 0; subex.Add(ex); expenses.subExpenses = subex; expenseInfo.Add(expenses); } Expense expense = new Expense(); expense.ExpenseDate = DateTime.Now; expense.JsonExpenseInfo = JsonConvert.SerializeObject(expenseInfo); _context.Add(follow); _context.Add(expense); _context.SaveChanges(); projectFollowUp.PfFollowUpId = follow.FuId; projectFollowUp.PfProject = p; projectExpense.PeExpenseId = expense.ExpenseId; projectExpense.PeProject = p; p.ProjectSoumission = JsonConvert.SerializeObject(soumission); Users user = new Users(); user = usermanager.FindUserByID(formCollection["Users"]); projectmanager.addProjet(p); projectFollowUp.PfFollowUp = follow; projectExpense.PeExpense = expense; _context.ProjectFollowUp.Add(projectFollowUp); _context.ProjectExpense.Add(projectExpense); _context.SaveChanges(); return(RedirectToAction("Index")); }
public FollowUserReturn FollowUser(string followedUsername, string followingId) { FollowUserReturn ret = new FollowUserReturn(); if (string.IsNullOrEmpty(followedUsername) || string.IsNullOrEmpty(followingId)) { ret.LastFollowState = FollowState.Unfollowed; ret.IsActionSucceed = false; return(ret); } UserInfo followedUser = _context.Set <UserInfo>().AsNoTracking().FirstOrDefault(f => f.UName == followedUsername); FollowInfo fInfo = _context.SetChild <FollowInfo>().FirstOrDefault(p => p.FollowerId == followingId && p.FollowedId == followedUser.AppUserId); if (followedUser.AppUserId == followingId) { ret.LastFollowState = FollowState.Unfollowed; ret.IsActionSucceed = false; return(ret); } if (fInfo == null) { FollowInfo newFollow = new FollowInfo() { FollowerId = followingId, FollowedId = followedUser.AppUserId, DateUtcFollowed = DateTime.UtcNow }; if (followedUser.FollowSetting == UserFollowSetting.Ask_All) { newFollow.FollowState = FollowState.Pending; ret.LastFollowState = FollowState.Pending; } else if (followedUser.FollowSetting == UserFollowSetting.Confirm_All) { newFollow.FollowState = FollowState.Confirmed; ret.LastFollowState = FollowState.Confirmed; } else if (followedUser.FollowSetting == UserFollowSetting.Deny_All) { ret.LastFollowState = FollowState.Unfollowed; return(ret); } ret.FollowedUserId = followedUser.AppUserId; _context.SetChild <FollowInfo>().Add(newFollow); } else { if (fInfo.FollowState == FollowState.FollowerBlocked_Followed || fInfo.FollowState == FollowState.FollowedBlocked_Follower) { ret.IsActionSucceed = false; ret.ErrorInformation.UserInformation = "Cannot follow blocked users."; ret.LastFollowState = FollowState.FollowedBlocked_Follower; } else if (fInfo.FollowState == FollowState.Unfollowed) { if (followedUser.FollowSetting == UserFollowSetting.Ask_All) { fInfo.FollowState = FollowState.Pending; ret.LastFollowState = FollowState.Pending; } else if (followedUser.FollowSetting == UserFollowSetting.Confirm_All) { fInfo.FollowState = FollowState.Confirmed; ret.LastFollowState = FollowState.Confirmed; } else if (followedUser.FollowSetting == UserFollowSetting.Deny_All) { ret.LastFollowState = FollowState.Unfollowed; return(ret); } } _context.SetChild <FollowInfo>().Update(fInfo); } if (_context.SaveChanges() != 0) { _userFollowCacheService.RemoveAllUserCache(followingId); ret.IsActionSucceed = true; } ; return(ret); }