public async Task <IActionResult> Create(int QuestionID, string UrlOriginalQuestion, [Bind("QuestionID,Id,Description,Date,UrlOriginalQuestion")] Answer answer) { SetActiveUser(); if (ModelState.IsValid) { string Activeuser = HttpContext.Session.GetString("USERNAME"); int activeUserId = _context.User.First(u => u.USERNAME.Equals(Activeuser)).ID; answer.Date = DateTime.Now; answer.UserId = activeUserId; _context.Add(answer); if (UrlOriginalQuestion != null) { _context.Question.Find(QuestionID).Insignia = "SEEN BEFORE"; } int questionOwner = _context.Question.Find(QuestionID).UserId.Value;// averiguo el dueño de la pregunta referencir a quien podra ver la notificacion Notification notification = new Notification { Read = false, UserID = questionOwner, TimeAnswer = answer.Date, QuestionId = QuestionID, Title = Activeuser + " Respondio tu pregunta " }; _context.Add(notification); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Details", "Questions", new { id = QuestionID })); } return(View(answer)); }
// POST: Views/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. public async Task <int> Create([Bind("ID,UserID,QuestionID")] View view) { if (ModelState.IsValid) { var lista = _context.View.Where(x => x.UserID == view.UserID && x.QuestionID == view.QuestionID).ToList(); if (lista.Count() > 0) { _context.View.Remove(lista.First()); await _context.SaveChangesAsync(); return(-1); } else { _context.Add(view); await _context.SaveChangesAsync(); return(1); } } ViewData["QuestionID"] = new SelectList(_context.Question, "Id", "Description", view.QuestionID); ViewData["UserID"] = new SelectList(_context.User, "ID", "ID", view.UserID); return(0); }
public async Task <IActionResult> CreateStudio(IFormFile file, [Bind("Id, Name, Unit, Description, Email")] Studio studio) { if (ModelState.IsValid) { _context.Add(studio); await _context.SaveChangesAsync(); var filePath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", studio.Name + ""); if (Directory.Exists(filePath)) { Directory.Delete(filePath, true); } Directory.CreateDirectory(filePath); filePath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", studio.Name + "", Path.GetFileName(file.FileName)); if (file.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } } } return(RedirectToAction(nameof(ManageStudios))); }
// POST: PositiveV/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. public async Task <int> Create([Bind("ID,UserID,AnswerID")] PositiveVote positiveVote) { if (ModelState.IsValid) { var lista = _context.PositiveVote.Where(x => x.UserID == positiveVote.UserID && x.AnswerID == positiveVote.AnswerID).ToList(); if (lista.Count() > 0) { _context.PositiveVote.Remove(lista.First()); await _context.SaveChangesAsync(); return(-1); } else { _context.Add(positiveVote); await _context.SaveChangesAsync(); return(1); } } return(0); }
public async Task <IActionResult> Create(int AnswerId, [Bind("AnswerId,Id,Description,Date")] Comment comment) { if (ModelState.IsValid) { string Activeuser = HttpContext.Session.GetString("USERNAME"); int activeUserId = _context.User.First(u => u.USERNAME.Equals(Activeuser)).ID; comment.UserId = activeUserId; comment.Date = DateTime.Now; _context.Add(comment); await _context.SaveChangesAsync(); var QuestionID = _context.Answer.Find(AnswerId).QuestionID; return(RedirectToAction("Details", "Questions", new { id = QuestionID })); } // ViewData["AnswerId"] = new SelectList(_context.Answer, "Id", "Description", comment.AnswerId); return(View(comment)); }
// POST: InterestingV/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. public async Task <int> Create([Bind("ID,UserID,QuestionID")] InterestingVote interestingVote) { if (ModelState.IsValid) { var lista = _context.InterestingVote.Where(x => x.UserID == interestingVote.UserID && x.QuestionID == interestingVote.QuestionID).ToList(); if (lista.Count() > 0) { _context.InterestingVote.Remove(lista.First()); await _context.SaveChangesAsync(); return(-1); } else { _context.Add(interestingVote); await _context.SaveChangesAsync(); return(1); } } return(0); }
public async Task <IActionResult> Create(int LEVEL, string USERNAME, string PASSWORD, string EMAIL, string PHOTO, int QUESTIONS_ANSWERED, int POSITIVE_VOTES_RECEIVED, int QUESTIONS_ASKED, int INTERESTING_VOTES_RECEIVED, string DESCRIPTION, string INTERESTS_OR_KNOWLEDGE, string COUNTRY, string CITY, string StudioName) { User user = new User(); user.LEVEL = LEVEL; user.USERNAME = USERNAME; user.PASSWORD = PASSWORD; user.EMAIL = EMAIL; user.PHOTO = PHOTO; user.QUESTIONS_ASKED = QUESTIONS_ASKED; user.QUESTIONS_ANSWERED = QUESTIONS_ANSWERED; user.POSITIVE_VOTES_RECEIVED = POSITIVE_VOTES_RECEIVED; user.INTERESTING_VOTES_RECEIVED = INTERESTING_VOTES_RECEIVED; user.DESCRIPTION = DESCRIPTION; user.INTERESTS_OR_KNOWLEDGE = INTERESTS_OR_KNOWLEDGE; user.COUNTRY = COUNTRY; user.CITY = CITY; user.StudioId = _context.Studio.FirstOrDefault(a => a.Name.Equals(StudioName)).Id; if (ModelState.IsValid) { bool exist = UserExists(user.USERNAME); string message = ""; if (exist) { message = "El usuario ya existe, digite uno nuevo"; } else { _context.Add(user); await _context.SaveChangesAsync(); message = "Cuenta creada, inicie sesión"; } return(RedirectToAction("Index", "Users", new { message })); } return(View(user)); }
public async Task <IActionResult> Create(List <IFormFile> files, string studio, string studio2, string studio3, string question_tags, [Bind("IsArchived,Id,Title,Description,IdUser,Date")] Question question) { User actualUser = null; if (!string.IsNullOrEmpty(HttpContext.Session.GetString(UsersController.ACTIVE_USERNAME))) { actualUser = model.GetUser(HttpContext.Session.GetString(UsersController.ACTIVE_USERNAME)); question.UserId = actualUser.ID; } if (ModelState.IsValid) { _context.Add(question); if (!string.IsNullOrEmpty(studio)) { var st = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio); if (!string.IsNullOrEmpty(question_tags)) { string[] tagsStr = question_tags.Split(","); foreach (string t in tagsStr) { var tag = await _context.Label.FirstOrDefaultAsync(m => m.Tag == t); if (tag == null) { tag = new Label(); tag.Tag = t; _context.Add(tag); } tag.NumberOfTimes++; var questionLabel = new QuestionLabel { LabelId = tag.Id, QuestionId = question.Id }; _context.Add(questionLabel); } } var st1 = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio); var questionStudio = new QuestionStudio { StudioId = st1.Id, QuestionId = question.Id }; _context.Add(questionStudio); if (studio2 != studio) { var st2 = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio2); var questionStudio2 = new QuestionStudio { StudioId = st2.Id, QuestionId = question.Id }; _context.Add(questionStudio2); } if (studio3 != studio && studio3 != studio2) { var st3 = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio3); var questionStudio3 = new QuestionStudio { StudioId = st3.Id, QuestionId = question.Id }; _context.Add(questionStudio3); } await _context.SaveChangesAsync(); var filePath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", question.Id + ""); if (Directory.Exists(filePath)) { Directory.Delete(filePath, true); } Directory.CreateDirectory(filePath); foreach (var formFile in files) { filePath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", question.Id + "", Path.GetFileName(formFile.FileName)); if (formFile.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await formFile.CopyToAsync(stream); } } } SendEmailStudio(question, st); } return(RedirectToAction(nameof(Index))); } return(View(question)); }
public async Task <IActionResult> Create(string action, List <IFormFile> files, string studio, string studio2, string studio3, string question_tags, [Bind("IsArchived,Id,Title,Description,IdUser,Date,question_tags")] Question question) { string user = SetActiveUser(); if (action == "Suggestions") { Suggestion(question.Title, question.Description); String[] q = { question.Title, question.Description }; TempData["question"] = q; } else if (action == "Ask now") { List <Studio> studios = new List <Studio>(); User actualUser = null; if (!string.IsNullOrEmpty(user)) { actualUser = model.GetUser(user); actualUser.QUESTIONS_ASKED++; question.UserId = actualUser.ID; } else { return(RedirectToAction("Index", "Users", new { message = "Inicie sesión" })); } if (ModelState.IsValid) { _context.Add(question); if (!string.IsNullOrEmpty(studio)) { //var st = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio); if (!string.IsNullOrEmpty(question_tags)) { string[] tagsStr = question_tags.Split(","); foreach (string t in tagsStr) { var tag = await _context.Label.FirstOrDefaultAsync(m => m.Tag == t); if (tag == null) { tag = new Label(); tag.Tag = t; _context.Add(tag); } tag.NumberOfTimes++; var questionLabel = new QuestionLabel { LabelId = tag.Id, QuestionId = question.Id }; _context.Add(questionLabel); } } var st1 = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio); var questionStudio = new QuestionStudio { StudioId = st1.Id, QuestionId = question.Id }; studios.Add(st1); _context.Add(questionStudio); if (studio2 != studio) { var st2 = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio2); var questionStudio2 = new QuestionStudio { StudioId = st2.Id, QuestionId = question.Id }; studios.Add(st2); _context.Add(questionStudio2); } if (studio3 != studio && studio3 != studio2) { var st3 = await _context.Studio.FirstOrDefaultAsync(m => m.Name == studio3); var questionStudio3 = new QuestionStudio { StudioId = st3.Id, QuestionId = question.Id }; studios.Add(st3); _context.Add(questionStudio3); } await _context.SaveChangesAsync(); var filePath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", question.Id + ""); if (Directory.Exists(filePath)) { Directory.Delete(filePath, true); } Directory.CreateDirectory(filePath); foreach (var formFile in files) { filePath = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", question.Id + "", Path.GetFileName(formFile.FileName)); if (formFile.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await formFile.CopyToAsync(stream); } } } SendEmailStudio(question, studios); } return(RedirectToAction(nameof(Index))); } } return(RedirectToAction(nameof(Create))); }