public IActionResult Create([FromBody] ProjectViewModel model) { List <object> Errors = new List <object>(); User user = userGetter.GetUser(); if (user is null) { return(BadRequest(Message.GetMessage("El usuari que intenta crear el projecte és incorrecte."))); } Project project = new Project { Id = Guid.NewGuid(), Description = model.Description, Title = model.Title, Background = model.Background, Icon = model.Icon, RepositoryUrl = model.RepositoryUrl, WebsiteUrl = model.WebsiteUrl, Owner = user }; Errors = Project.ValidateProject(project); if (Errors.Count >= 1) { return(BadRequest(Errors)); } db.Projects.Add(project); db.SaveChanges(); return(new JsonResult(Message.GetMessage("S'ha creat el projecte correctament"))); }
public IEnumerable <ForumListViewModel> GetForumsSubscribedUser(string id_user) { User user = null; try { user = userGetter.GetUser(id_user); List <Wallet> Wallets = db.Wallets.Where(x => x.User.Id.ToString() == id_user).Include(x => x.Forum).ToList(); List <ForumListViewModel> Forums = new List <ForumListViewModel>(); foreach (var wallet in Wallets) { ForumListViewModel forum = db.Forums.Join(db.Users, x => x.Owner.IdentityId, us => us.Id, (x, us) => new ForumListViewModel { Id = x.Id.ToString(), Title = x.Title, Description = x.Description, Background = x.Background, DateBeginsVote = x.DateBeginsVote, DateEndsVote = x.DateEndsVote, CreationDate = x.CreationDate, Icon = x.Icon, Views = x.Views, Owner = new UserViewModel { Id = x.Owner.Id, Avatar = x.Owner.Avatar, Description = x.Owner.Description, WebsiteUrl = x.Owner.WebsiteUrl, RepositoryUrl = x.Owner.RepositoryUrl, FacebookUrl = x.Owner.FacebookUrl, TwitterUrl = x.Owner.TwitterUrl, Name = us.Name, Surname = us.Surname, Email = us.Email } }).Where(x => x.Id == wallet.Forum.Id.ToString()).FirstOrDefault(); if (forum != null) { Forums.Add(forum); } } return(Forums); } catch (Exception) { return(null); } }
public IActionResult Vote([FromBody] VoteViewModel model) { Project ProjectToSearch = db.Projects.Where(x => x.Id.ToString() == model.ProjectId).Include(x => x.Forum).FirstOrDefault(); if (ProjectToSearch is null) { return(BadRequest(Message.GetMessage("Aquest projecte no existeix."))); } Forum ForumToSearch = ProjectToSearch.Forum; if (ForumToSearch is null) { return(BadRequest(Message.GetMessage("Aquest projecte no esta inscrit a cap forum per poder votar-lo."))); } User user = userGetter.GetUser(); if (user is null) { return(BadRequest(Message.GetMessage("T'has de loguejar per poder votar."))); } Wallet WalletToSearch = db.Wallets.Where(x => x.ForumId == ForumToSearch.Id && x.UserId == user.Id).FirstOrDefault(); if (WalletToSearch is null) { return(BadRequest(Message.GetMessage("El usuari no participa en el forum per podar votar en el projecte."))); } BillOption BillToSearch = db.BillOptions.Where(x => x.Value == int.Parse(model.Value) && x.WalletId == WalletToSearch.Id).FirstOrDefault(); if (BillToSearch is null) { return(BadRequest(Message.GetMessage("El usuari no te aquesta opció de vot."))); } /*if (ForumToSearch.DateBeginsVote.Date >= DateTime.Now.Date && DateTime.Now.Date <= ForumToSearch.DateEndsVote.Date) * {*/ Vote vote = new Vote { ImgUri = BillToSearch.ImgUri, Name = BillToSearch.Name, Value = BillToSearch.Value, Project = ProjectToSearch }; ProjectToSearch.TotalMoney += vote.Value; db.Remove(BillToSearch); db.Votes.Add(vote); db.Projects.Update(ProjectToSearch); db.SaveChanges(); return(new JsonResult(Message.GetMessage("El vot s'ha realitzat correctament."))); //} return(BadRequest(Message.GetMessage("No s'ha pogut realitzar el vot perquè la data actual no està dintre del termini de vot del Forum."))); }
public IActionResult GetSubscribed([FromRoute] string id_forum) { User user = userGetter.GetUser(); if (user is null) { return(BadRequest(Message.GetMessage("No hi ha cap usuari connectat."))); } Wallet wallet = db.Wallets.Where(x => x.User.Id == user.Id && x.Forum.Id.ToString() == id_forum).Include(x => x.User).Include(x => x.Forum).FirstOrDefault(); if (wallet is null) { return(BadRequest()); } return(new OkResult()); }
public IActionResult Get() { User user = userGetter.GetUser(); if (user is null) { return(BadRequest(Message.GetMessage("No hi ha cap usuari connectat per poder visualtizar les dades."))); } UserViewModel model = new UserViewModel { Id = user.Id, Avatar = user.Avatar, Name = user.Identity.Name, Surname = user.Identity.Surname, Description = user.Description, Email = user.Identity.Email, FacebookUrl = user.FacebookUrl, RepositoryUrl = user.RepositoryUrl, TwitterUrl = user.TwitterUrl, WebsiteUrl = user.WebsiteUrl }; return(new JsonResult(model)); }