public static void UpdateGoal(dynamic metadata, dynamic content) { var text = content.Text.ToString(); var id = content.Id.ToString(); var groupKey = metadata.GroupKey.ToString(); var memberKey = metadata.MemberKey.ToString(); var goal = Goals.SingleOrDefault(t => t.Id == id); if (goal != null) { goal.Text = text; } else { SendFeedbackMessage(type: MsgType.Error, actionTime: GetCreateDate(metadata), action: MapAction.GoalFeedback.CannotUpdateGoal.Name, content: "Cannot update Goal"); } }
internal static void DeleteGoal(dynamic metadata, dynamic content) { var id = content.Id.ToString(); var Goal = Goals.SingleOrDefault(t => t.Id == id); var groupKey = metadata.GroupKey.ToString(); var memberKey = metadata.MemberKey.ToString(); if (Goal != null) { Goals.Remove(Goal); SendFeedbackMessage(type: MsgType.Success, actionTime: GetCreateDate(metadata), action: MapAction.GoalFeedback.GoalDeleted.Name, content: new { Id = id }); } else { SendFeedbackMessage(type: MsgType.Error, actionTime: GetCreateDate(metadata), action: MapAction.GoalFeedback.CannotFindGoal.Name, content: "Cannot find Goal item!"); } }
public void SynchEntities() { try { var scales = client.GetAllScales(); foreach (var a in scales) { var scale = Scales.SingleOrDefault(q => q.ID == a.Id); if (scale == null) { Scales.Add(new Scale(a.Id, a.Name)); } else { scale.Update(a.Name); } } var sports = client.GetAllSports(); foreach (var a in sports) { var sport = Sports.SingleOrDefault(q => q.ID == a.Id); if (sport == null) { sport = new Sport(a.Id, a.Name); Sports.Add(sport); } else { sport.Update(a.Name); } var disciplines = client.GetDiscipliniesFromSport(a.Id); foreach (var disc in disciplines) { var discipline = Disciplines.SingleOrDefault(q => q.ID == disc.Id); if (discipline == null) { discipline = new Discipline(disc.Id, disc.Name, sport, Scales.Single(q => q.ID == disc.ScaleId), disc.Description); Disciplines.Add(discipline); } else { discipline.Update(disc.Name, sport, Scales.Single(q => q.ID == disc.ScaleId), disc.Description); } var goals = client.GetGoalsFromDiscipline(disc.Id); foreach (var g in goals) { var goal = Goals.SingleOrDefault(q => q.ID == g.Id); if (goal == null) { goal = new Goal(g.Id, g.Value, discipline, g.PeriodDays, g.Description, Users.SingleOrDefault(q => q.ID == g.OwnerId)); Goals.Add(goal); } else { goal.Update(g.Value, discipline, g.PeriodDays, g.Description, Users.Single(q => q.ID == g.OwnerId)); } var users_goals = client.GetUsers_GoalsFromUser(CurrentUser.ID, goal.ID); foreach (var userg in users_goals) { var user_goal = Users_Goals.SingleOrDefault(q => q.ID == userg.Id); if (user_goal == null) { user_goal = new User_Goal(userg.Id, CurrentUser, goal, userg.DateStart); Users_Goals.Add(user_goal); } else { user_goal.Update(CurrentUser, goal, userg.DateStart); } var stand_datas = client.GetStandart_DataFromGoal(user_goal.Goal.ID); foreach (var s in stand_datas) { var stand = Standarts_Datas.SingleOrDefault(q => q.ID == s.Id); if (stand == null) { stand = new Standart_Data(s.Id, s.Value, user_goal.Goal, s.Day); Standarts_Datas.Add(stand); } else { stand.Update(s.Value, user_goal.Goal, s.Day); } } var users_data = client.GetUsers_DataFromGoal(userg.GoalId); foreach (var us in users_data) { var user_data = Users_Datas.SingleOrDefault(q => q.ID == us.Id); if (user_data == null) { user_data = new User_Data(us.Id, user_goal, us.Value, us.Date); Users_Datas.Add(user_data); } else { user_data.Update(user_goal, us.Value, us.Date); } } } } } } } catch (Exception e) { } SaveBinaryFormat(); }