Пример #1
0
        public Result <List <string> > ViewByCategory(string category)
        {
            var context            = new CrowDoDbContext();
            var projectsByCategory = new List <string>();
            var punctuation        = category.Where(char.IsPunctuation).Distinct().ToArray();
            var wordsOfCategory    = category.Split().Select(x => x.Trim(punctuation));
            var projects           = context.Set <ProjectProfilePage>();

            foreach (var wrd in wordsOfCategory)
            {
                foreach (var p in projects)
                {
                    if (p.Category == null)
                    {
                        continue;
                    }
                    string categry      = p.Category;
                    var    punctuation1 = categry.Where(char.IsPunctuation).Distinct().ToArray();
                    var    words        = categry.Split().Select(x => x.Trim(punctuation1));
                    foreach (var c in words)
                    {
                        if (c == wrd)
                        {
                            projectsByCategory.Add(p.Title);
                        }
                    }
                }
            }
            return(new Result <List <string> > {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = projectsByCategory
            });
        }
Пример #2
0
        public Result <bool> DeleteAccount(string name, string email)
        {
            var context = new CrowDoDbContext();

            if (IsValidEmail(email) == false)
            {
                return(new Result <bool> {
                    ErrorCodeId = 1, ErrorCodeString = "Invalid Email", Data = false
                });
            }
            var user = context.Set <User>().Where(User => User.Email == email).SingleOrDefault();

            if (user == null)
            {
                return(new Result <bool> {
                    ErrorCodeId = 2, ErrorCodeString = "Email does not exist", Data = false
                });
            }
            user.Activity = false;
            context.Update(user);

            var rowsAffected = context.SaveChanges();

            if (rowsAffected < 1)
            {
                return(new Result <bool> {
                    ErrorCodeId = 3, ErrorCodeString = "Nothing Saved", Data = false
                });
            }

            return(new Result <bool> {
                ErrorCodeId = 0, ErrorCodeString = "Account Deactivated", Data = true
            });
        }
Пример #3
0
        public void ReadCreatorFromFile(string fileName)
        { //Create new project
            using (StreamReader r = new StreamReader($@"{fileName}.json"))
            {
                string json = r.ReadToEnd();
                List <CreatorFromfile> creatorsFromFile = JsonConvert.DeserializeObject <List <CreatorFromfile> >(json);
                var users = new List <User>();

                foreach (CreatorFromfile c in creatorsFromFile)
                {
                    var user = new User
                    {
                        Name     = c.Name,
                        Email    = c.Email,
                        Location = c.Address,
                    };
                    users.Add(user);
                }
                var context = new CrowDoDbContext();
                foreach (User u in users)
                {
                    context.Add(u);
                    context.SaveChanges();
                }
            }
        }
Пример #4
0
        public Result <List <string> > ViewByText(string text)
        {
            var context     = new CrowDoDbContext();
            var punctuation = text.Where(char.IsPunctuation).Distinct().ToArray();
            var words       = text.Split().Select(x => x.Trim(punctuation));
            var projects    = context.Set <ProjectProfilePage>();
            // var foundprojects = new List<ProjectProfilePage>();
            var results = new List <string>();

            foreach (var word in words)
            {
                foreach (var p in projects)
                {
                    var array = p.Title.Split(' ');
                    foreach (var a in array)
                    {
                        if (word == a)
                        {
                            results.Add(p.Title);
                        }
                    }
                }
            }
            return(new Result <List <string> > {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = results
            });
        }
Пример #5
0
        public List <ProjectProfilePage> RecentProjects()
        {
            DateTime lastYear       = DateTime.Today.AddYears(-1);
            var      context        = new CrowDoDbContext();
            var      recentProjects = context.Set <ProjectProfilePage>().Where(p => DateTime.Compare(lastYear, p.DateOfCreation) < 0).ToList();

            return(recentProjects);
        }
Пример #6
0
        public List <ProjectProfilePage> MonthlyProjectsToXls()
        {
            DateTime aMonthAgo        = DateTime.Today.AddDays(-30);
            var      context          = new CrowDoDbContext();
            var      lastWeekProjects = context.Set <ProjectProfilePage>().Where(p => DateTime.Compare(aMonthAgo, p.DateOfCreation) < 0).ToList();

            SaveToXls("WeeklyProjects", lastWeekProjects);
            return(lastWeekProjects);
        }
Пример #7
0
        public Result <string> MostVisitedProject()
        {
            var    context  = new CrowDoDbContext();
            var    maxView  = context.Set <ProjectProfilePage>().OrderByDescending(view => view.ViewsCounter).Max();
            string maxViewd = maxView.Title;

            return(new Result <string> {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = maxViewd
            });
        }
Пример #8
0
        public List <User> TopCreators()
        {
            var context     = new CrowDoDbContext();
            var topCreators = context.Set <User>()
                              .OrderByDescending(u => u.ViewsCounter)
                              .Take(20)
                              .ToList();

            return(topCreators);
        }
Пример #9
0
        public List <ProjectProfilePage> MostVisitedProjects()
        {
            var context     = new CrowDoDbContext();
            var topCreators = context.Set <ProjectProfilePage>()
                              .OrderByDescending(u => u.ViewsCounter)
                              .Take(5)
                              .ToList();

            return(topCreators);
        }
        public Result <bool> AddProject(string email, ProjectProfilePage project)
        {
            var context       = new CrowDoDbContext();
            var projectExists = context.Set <ProjectProfilePage>().Where(p => p.Title == project.Title).Any();

            if (projectExists)
            {
                return(new Result <bool> {
                    ErrorCodeId = 1, ErrorCodeString = "Project already exists", Data = false
                });
            }
            var user = context.Set <User>().Where(c => c.Email == email).SingleOrDefault();

            if (user == null)
            {
                return(new Result <bool> {
                    ErrorCodeId = 2, ErrorCodeString = "Creator does not exist", Data = false
                });
            }
            var categoryExists = context.Set <Category>().Where(c => c.Name == project.Category).SingleOrDefault();;

            if (categoryExists == null)
            {
                var newCategory = new Category
                {
                    Name = project.Category
                };
                newCategory.Projects.Add(project);
                context.Add(newCategory);
            }
            else
            {
                categoryExists.Projects.Add(project);
                context.Update(categoryExists);
            }

            project.Creator = user;
            user.CreatedProjects.Add(project);
            context.Update(user);
            context.Add(project);
            if (context.SaveChanges() < 1)
            {
                return(new Result <bool> {
                    ErrorCodeId = 3, ErrorCodeString = "Not Saved", Data = false
                });
            }

            return(new Result <bool> {
                ErrorCodeId = 0, ErrorCodeString = "Project created", Data = true
            });
        }
Пример #11
0
        public Result <List <string> > ViewProjects()
        {
            var context     = new CrowDoDbContext();
            var projects    = context.Set <ProjectProfilePage>().ToList();
            var allProjects = new List <string>();

            foreach (var p in projects)
            {
                allProjects.Add(p.Title);
                //Console.WriteLine($"{p.Title}");
            }
            return(new Result <List <string> > {
                ErrorCodeId = 0, ErrorCodeString = "ok", Data = allProjects
            });
        }
Пример #12
0
        public Result <List <string> > ViewByCreator(string name)
        {
            var context     = new CrowDoDbContext();
            var projectList = context.Set <ProjectProfilePage>()
                              .Where(p => p.Creator.Name == name).ToList();

            var results = new List <string>();

            foreach (var project in projectList)
            {
                results.Add(project.Title);
                //Console.WriteLine($"Title: {project.Title}");
            }
            return(new Result <List <string> > {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = results
            });
        }
        public Result <bool> DeletePhoto(string projectName, string photoName)
        {
            var context = new CrowDoDbContext();
            var project = context.Set <ProjectProfilePage>().SingleOrDefault(p => p.Title == projectName);
            var photo   = context.Set <Photos>().SingleOrDefault(l => l.Name == photoName);

            if (photo != null)
            {
                context.Remove(photo);
                context.SaveChanges();
                return(new Result <bool> {
                    ErrorCodeId = 0, ErrorCodeString = "OK", Data = true
                });
            }
            return(new Result <bool> {
                ErrorCodeId = 1, ErrorCodeString = "Photo Not Found", Data = false
            });
        }
Пример #14
0
        public Result <List <string> > ViewcompletedProjects()
        {
            var context           = new CrowDoDbContext();
            var projects          = context.Set <ProjectProfilePage>();
            var completedProjects = new List <string>();

            foreach (var p in projects)
            {
                if (p.Active == false)
                {
                    completedProjects.Add(p.Title);
                    //Console.WriteLine(p.ToString());
                }
            }
            return(new Result <List <string> > {
                ErrorCodeId = 0, ErrorCodeString = "Package Created", Data = completedProjects
            });
        }
Пример #15
0
        public List <ProjectProfilePage> BackersFundedProjects(string email)
        {
            var context        = new CrowDoDbContext();
            var fundedProjects = new List <ProjectProfilePage>();
            var user           = context.Set <User>().SingleOrDefault(e => e.Email == email);
            int id             = user.UserId;
            var proj           = context.Set <UserProject>().Where(u => u.UserId == id);

            foreach (var f in proj)
            {
                var fp = context.Set <ProjectProfilePage>().Where(pid => pid.ProjectProfilePageId == f.ProjectProfilePageId);
                foreach (var item in fp)
                {
                    fundedProjects.Add(item);
                    Console.WriteLine($"{item.Title},{item.Balance}");
                }
            }
            return(fundedProjects);
        }
Пример #16
0
        public Result <List <ProjectProfilePage> > FundedProjects(string email)
        {
            var context        = new CrowDoDbContext();
            var fundedProjects = new List <ProjectProfilePage>();
            var user           = context.Set <User>().SingleOrDefault(e => e.Email == email);
            int id             = user.UserId;
            var proj           = context.Set <UserProject>().Where(u => u.UserId == id);

            foreach (var f in proj)
            {
                var fp = context.Set <ProjectProfilePage>().Where(pid => pid.ProjectProfilePageId == f.ProjectProfilePageId);
                foreach (var item in fp)
                {
                    fundedProjects.Add(item);
                }
            }
            return(new Result <List <ProjectProfilePage> > {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = fundedProjects
            });
        }
        public Result <bool> ProjectEdit(string currenttitle, string title, string description, DateTime deadline)
        {
            var context = new CrowDoDbContext();
            var project = context.Set <ProjectProfilePage>().SingleOrDefault(c => c.Title == currenttitle);

            if (project == null)
            {
                return(new Result <bool> {
                    ErrorCodeId = 0, ErrorCodeString = "Project not found", Data = false
                });
            }
            project.Title       = title;
            project.Description = description;
            project.DeadLine    = deadline;
            context.SaveChanges();

            return(new Result <bool> {
                ErrorCodeId = 0, ErrorCodeString = "Project edited", Data = true
            });
        }
        public Result <bool> AddPhoto(string projectName, string photoName)
        {
            var context  = new CrowDoDbContext();
            var newPhoto = new Photos
            {
                Name = photoName
            };
            var project = context.Set <ProjectProfilePage>().SingleOrDefault(p => p.Title == projectName);

            if (project == null)
            {
                return(new Result <bool> {
                    ErrorCodeId = 1, ErrorCodeString = "Project Not Found", Data = true
                });
            }
            project.Photos.Add(newPhoto);
            context.SaveChanges();
            return(new Result <bool> {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = true
            });
        }
Пример #19
0
        public Result <List <string> > ViewDetailsOfProject(string title)
        {
            var context = new CrowDoDbContext();
            var project = context.Set <ProjectProfilePage>().Where(p => p.Title == title).Include(p => p.Creator).SingleOrDefault();
            var details = new List <string>
            {
                project.Title,
                project.Description,
                project.DateOfCreation.ToString(("yyyy-mm-dd")),
                project.DeadLine.ToString(("yyyy-mm-dd")),
                $"{project.Goal}",
                project.Category
            };

            project.ViewsCounter += 1;



            return(new Result <List <string> > {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = details
            });
        }
Пример #20
0
        public Result <bool> FundProject(string email, string projectName, decimal amount) //string titleOfPackage)
        {
            var context = new CrowDoDbContext();
            var project = context.Set <ProjectProfilePage>().SingleOrDefault(p => p.Title == projectName);

            if (project == null)
            {
                return(new Result <bool> {
                    ErrorCodeId = 1, ErrorCodeString = "Project Not Found", Data = true
                });
            }
            var user = context.Set <User>().SingleOrDefault(u => u.Email == email);

            if (user == null)
            {
                return(new Result <bool> {
                    ErrorCodeId = 0, ErrorCodeString = "Email doesnt exist", Data = true
                });
            }
            if (!user.Activity)
            {
                user.Activity = true;
            }
            var fp = new UserProject();

            user.UserProject.Add(fp);
            project.UserProject.Add(fp);
            project.Balance += amount;
            if (project.Balance >= project.Goal)
            {
                project.Active = false;
                context.SaveChanges();
            }
            context.SaveChanges();
            return(new Result <bool> {
                ErrorCodeId = 0, ErrorCodeString = "Project Funded", Data = true
            });
        }
Пример #21
0
        public Result <List <string> > ViewByYear(int year)
        {
            string yr             = year.ToString();
            var    context        = new CrowDoDbContext();
            var    projects       = context.Set <ProjectProfilePage>();
            var    listOfProjects = new List <string>();

            foreach (var p in projects)
            {
                var array = p.DateOfCreation.ToString("yyyy-mm-dd").Split(new char[] { ' ', '/', '-' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var a in array)
                {
                    if (a == yr)
                    {
                        listOfProjects.Add(p.Title);
                    }
                }
            }
            return(new Result <List <string> > {
                ErrorCodeId = 0, ErrorCodeString = "OK", Data = listOfProjects
            });
        }
Пример #22
0
        public Result <bool> EditAccount(string name, string email, DateTime dateOfBirth, string location, string cardNumber)
        {
            var context = new CrowDoDbContext();

            if (IsValidEmail(email) == false)
            {
                return(new Result <bool> {
                    ErrorCodeId = 1, ErrorCodeString = "Invalid Email", Data = false
                });
            }
            var user = context.Set <User>().SingleOrDefault(User => User.Email == email);

            if (user == null)
            {
                return(new Result <bool> {
                    ErrorCodeId = 2, ErrorCodeString = "Email does not exists", Data = false
                });
            }
            user.Name           = name;
            user.Email          = email;
            user.DateOfBirth    = dateOfBirth;
            user.DateOfRegister = DateTime.Now;
            user.Location       = location;
            user.CardNumber     = cardNumber;
            var rowsAffected = context.SaveChanges();

            if (rowsAffected < 1)
            {
                return(new Result <bool> {
                    ErrorCodeId = 3, ErrorCodeString = "Nothing Saved", Data = false
                });
            }
            return(new Result <bool> {
                ErrorCodeId = 0, ErrorCodeString = "Changes have been saved", Data = false
            });
        }
Пример #23
0
        public Result <bool> CreateAccount(string name, string email, DateTime dateOfBirth, string location, string cardNumber)
        {
            var context = new CrowDoDbContext();

            if (IsValidEmail(email) == false)
            {
                return(new Result <bool> {
                    ErrorCodeId = 1, ErrorCodeString = "Invalid Email", Data = false
                });
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                return(new Result <bool> {
                    ErrorCodeId = 2, ErrorCodeString = "Null Or WhiteSpaceName", Data = false
                });
            }

            if (dateOfBirth.AddYears(18) > DateTime.Now)
            {
                return(new Result <bool> {
                    ErrorCodeId = 3, ErrorCodeString = "Not an adult", Data = false
                });
            }

            if (cardNumber.ToString().Length != 16)
            {
                return(new Result <bool> {
                    ErrorCodeId = 4, ErrorCodeString = "Invalid Card", Data = false
                });
            }

            var usrexist = context.Set <User>().Where(c => c.CardNumber == cardNumber).Any();

            if (usrexist)
            {
                return(new Result <bool> {
                    ErrorCodeId = 5, ErrorCodeString = "Card already exist, enter another card", Data = false
                });
            }


            var userexist = context.Set <User>().Where(u => u.Email == email).Any();


            if (userexist)
            {
                return(new Result <bool> {
                    ErrorCodeId = 6, ErrorCodeString = "Email belongs to another user", Data = false
                });
            }
            var user = new User
            {
                Name           = name,
                Email          = email,
                DateOfBirth    = dateOfBirth,
                DateOfRegister = DateTime.Now,
                Location       = location,
                CardNumber     = cardNumber
            };

            context.Add(user);


            var rowsAffected = context.SaveChanges();

            if (rowsAffected < 1)
            {
                return(new Result <bool> {
                    ErrorCodeId = 6, ErrorCodeString = "Nothing saved", Data = false
                });
            }

            return(new Result <bool> {
                ErrorCodeId = 0, ErrorCodeString = "User Created", Data = true
            });
        }