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 }); }
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(); } } }
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 }); }
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 }); }
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 }); }
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 }); }
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 }); }
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 }); }