Beispiel #1
0
 public List<User> GetBestUsers(int count)
 {
     List<User> lst;
     using (var db = new DataContext())
     {
         lst = db.Users.OrderByDescending(user => user.Rate).Take(count).ToList();
     }
     return lst;
 }
Beispiel #2
0
 public CourseDatabase()
 {
     Context = new DataContext();
     Tasks = new TaskRepository(Context);
     Users = new UserRepository(Context);
     Tags = new TagsRepository(Context);
     Answers = new AnswerRepository(Context);
     Search = new SearchRepository();
 }
Beispiel #3
0
 public List<Tag> GetPopularTags(int count)
 {
     List<Tag> lst;
     using (var db = new DataContext())
     {
         lst = db.Tags.OrderBy(tag => tag.Tasks.Count()).Take(count).ToList();
     }
     return lst;
 }
Beispiel #4
0
 /// <summary>
 /// Delete Task specified in TaskModel.
 /// </summary>
 /// <param name="deleteTaskModel">TaskModel of Task to delete.</param>
 public void DeleteTask(TaskModel deleteTaskModel)
 {
     using (var db = new DataContext())
     {
         var userProvider = new UserProvider();
         User currentUser = userProvider.GetCurrentUser(db);
         var deletingTask = currentUser.Tasks.FirstOrDefault(deleteTask => deleteTask.Title == deleteTaskModel.Title);
         currentUser.Tasks.Remove(deletingTask);
         db.SaveChanges();
     }
 }
Beispiel #5
0
 public void AddTask(TaskModel model)
 {
     using (var db = new DataContext())
     {
          var tag = new Tag {TagId = Guid.NewGuid(), TagName = "dasd"};
         var newTask = new Task
                            {
                                TaskId = Guid.NewGuid(),
                                Title = model.Title,
                                CreationDate = DateTime.UtcNow,
                            };
         db.Tags.Add(tag);
         newTask.Tags.Add(tag);
         var userProvider = new UserProvider();
         userProvider.GetCurrentUser(db).Tasks.Add(newTask);
         newTask.UserOwner = userProvider.GetCurrentUser(db);
         db.Tasks.Add(newTask);
         db.SaveChanges();
     }
 }
Beispiel #6
0
 private IEnumerable<Tag> InitializeTags(DataContext db,IEnumerable<String> tagNames)
 {
     var tags = new List<Tag>();
     foreach (var tagString in tagNames)
     {
         var tag = db.Tags.Create();
         tag.TagId = Guid.NewGuid();
         tag.TagName = tagString;
         tags.Add(tag);
     }
     return tags;
 }
Beispiel #7
0
 public void LikeTask(Guid id)
 {
     using (var db = new DataContext())
     {
         var userProvider = new UserProvider();
         Task task = GetTaskById(id);
         if (!userProvider.IsUserLikedTask(db,task))
         {
             userProvider.AddTaskLiked(db,task);
             IncrementLikes(id);
        //     DbContext.Entry(user).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
 }
Beispiel #8
0
 public Task GetTaskById(Guid id)
 {
     using (var db = new DataContext())
     {
         return db.Tasks.FirstOrDefault(task => task.TaskId == id);
     }
 }
Beispiel #9
0
 public List<Task> GetLastTasks()
 {
     List<Task> lst;
     using (var db = new DataContext())
     {
         lst = db.Tasks.OrderByDescending(task => task.CreationDate).Take(10).ToList();
     }
     return lst;
 }
Beispiel #10
0
        public static MembershipCreateStatus Register(string username, string password, string email, bool IsApproved)
        {
            MembershipCreateStatus createStatus;
            System.Web.Security.Membership.CreateUser(username, password, email, null, null, IsApproved, Guid.NewGuid(), out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {
                using (var context = new DataContext())
                {
                    context.SaveChanges();
                }
            }

            return createStatus;
        }
Beispiel #11
0
 public void AddTaskLiked(DataContext db, Task task)
 {
     this.GetCurrentUser(db).TasksLiked.Add(task);
 }
Beispiel #12
0
 public bool IsUserLikedTask(DataContext db, Task task)
 {
     return this.GetCurrentUser(db).TasksLiked.Find(taskFind => taskFind.TaskId == task.TaskId) != null;
 }
Beispiel #13
0
 public IEnumerable<Task> GetAllTasksByUserName(string username)
 {
     using (var db = new DataContext())
     {
         var userProvider = new UserProvider();
         return userProvider.GetUserByUsername(db, username).Tasks;
     }
 }
Beispiel #14
0
 public List<Tag> GetPopularTags(DataContext db,int count)
 {
     return db.Tags.OrderBy(tag => tag.Tasks.Count()).Take(count).ToList();
 }
 public void AddCathegory(DataContext db,CathegoryModel model)
 {
     Cathegory newCathegory = db.Cathegories.Create();
     InitializeCathegory(model,newCathegory);
     db.SaveChanges();
 }
Beispiel #16
0
 public User GetUserByUsername(DataContext db, String username)
 {
     return db.Users.FirstOrDefault(user => user.Username == username);
 }
Beispiel #17
0
 public User GetUserById(DataContext db, Guid id)
 {
     return db.Users.FirstOrDefault(user => user.UserId == id);
 }
Beispiel #18
0
 public User GetCurrentUser(DataContext db)
 {
     return this.GetUserByUsername(db,WebSecurity.User.Identity.Name);
 }
Beispiel #19
0
 public Tag GetTagById(DataContext db, Guid id)
 {
     return db.Tags.First(tag => tag.TagId == id);
 }
Beispiel #20
0
 public IEnumerable<Task> GetTagTasks(DataContext db, Guid id, int count)
 {
     Tag selectedTag = GetTagById(db, id);
     return selectedTag.Tasks.Take(count);
 }
Beispiel #21
0
 /// <summary>
 /// Return all currnet User Tasks 
 /// </summary>
 /// <returns>UserTasks</returns>
 public IEnumerable<Task> GetCurrentUserTasks()
 {
     using (var db = new DataContext())
     {
         var userProvider = new UserProvider();
         return userProvider.GetCurrentUser(db).Tasks;
     }
 }
Beispiel #22
0
 public IEnumerable<User> GetUsers(DataContext db, int index, int count)
 {
     return db.Users.Skip(index).Take(count);
 }