private void AddAnalyse_Click_1(object sender, EventArgs e) { AnalyseModel addmodel = new AnalyseModel(); DateModel datemodel = new DateModel(); datemodel.Day = Program.Current_Date.Date; datemodel.Time += Program.Current_Date.TimeOfDay; addmodel.Date_Id = date.Add(datemodel); try { int selected = ListView.SelectedIndices[0]; addmodel.Type_Id = Analyse_Type.SelectedIndex + 1; addmodel.Client_Id = long.Parse(ListView.Items[selected].SubItems[0].Text); addmodel.Result = long.Parse(ResultText.Text); addmodel.Coment = Coment.Text; analyse.Add(addmodel); Coment.Clear(); ResultText.Clear(); MessageBox.Show("Данные внесены"); } catch { MessageBox.Show("Некоторые поля не выбраны"); } }
/// <summary> /// 通过评论ID获取评论信息 /// </summary> /// <param name="ID"></param> /// <returns></returns> public Coment GetComentInfo(string ID) { //执行数据库操作 OracleDataReader rd = dBAccess.GetDataReader(dBAccess.Select("*", "coment", "id='" + ID + "'")); //创建Coment对象 Coment coment = new Coment(); //读取数据 if (rd.Read()) { coment.ID = rd[0].ToString(); coment.Content = rd[1].ToString(); coment.SendTime = rd[2].ToString(); if (rd[3] is DBNull) { coment.QuoteID = null; } else { coment.QuoteID = rd[3].ToString(); } coment.Type = rd[4].ToString(); } //返回对象 return(coment); }
static void Main(string[] args) { //StringBuilder manipula textos Coment coment1 = new Coment("Have a nice trip"); Coment coment2 = new Coment("Wow That's awesome!"); Post p1 = new Post( DateTime.Parse("21/06/2018 13:05:44"), "Travalling to New Zealand", "I am going to visit this wonderful country", 12); p1.AddComent(coment1); p1.AddComent(coment2); Coment coment3 = new Coment("Good night"); Coment coment4 = new Coment("May the force be with you"); Post p2 = new Post( DateTime.Parse("28/07/2018 2:14:19"), "Good night guys", "See you tomorrow", 5); p2.AddComent(coment3); p2.AddComent(coment4); Console.WriteLine(p1); Console.WriteLine(p2); }
static void Main(string[] args) { Coment c1 = new Coment("Have a nice strip"); Coment c2 = new Coment("Wow that's awesome!"); Post p1 = new Post( DateTime.Parse("21/6/2018 13:05:44"), "Traveling to new Zealand", "I'm going to visit this wonderfaul country", 12 ); p1.AddComent(c1); p1.AddComent(c2); Coment c3 = new Coment("Good night"); Coment c4 = new Coment("May the Force be with you"); Post p2 = new Post( DateTime.Parse("28/6/2018 13:05:44"), "Good night guys", "See you tomorrow", 5 ); p2.AddComent(c3); p2.AddComent(c4); Console.WriteLine(p1); Console.WriteLine(p2); }
public bool DeleteComent(Coment coment) { var parameters = new DataAccessParameter[1]; parameters[0] = new DataAccessParameter("@ComentId", coment.ComentId, typeof(int), null, ParameterDirection.Input); return(1 == WikiDBAdapter.ExecuteStoredProcedure("DeleteComent", parameters)); }
public IActionResult Create(int id) { var coment = new Coment { driverId = id, createdAt = DateTime.Now }; return(View(coment)); }
public bool InsertComent(Coment coment) { var parameters = new DataAccessParameter[4]; parameters[0] = new DataAccessParameter("@PostId", coment.Post.PostId, typeof(int), null, ParameterDirection.Input); parameters[1] = new DataAccessParameter("@ComentReferenceId", coment.ComentReferenceId, typeof(int), null, ParameterDirection.Input); parameters[2] = new DataAccessParameter("@ComentText", coment.ComentText, typeof(int), null, ParameterDirection.Input); parameters[3] = new DataAccessParameter("@UserId", coment.User.UserId, typeof(int), null, ParameterDirection.Input); return(1 == WikiDBAdapter.ExecuteStoredProcedure("InsertComent", parameters)); }
public async Task <ActionResult> DeleteConfirmed(int id) { Coment coment = await db.comments.FindAsync(id); int post_id = coment.post.id; db.comments.Remove(coment); await db.SaveChangesAsync(); return(RedirectToAction("Index", "Discussion", new { id = post_id })); }
public async Task <ActionResult> Edit([Bind(Include = "id,text")] Coment coment) { if (ModelState.IsValid) { db.Entry(coment).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index", "Discussion")); } return(View(coment)); }
public void AddComment(string filmName, string comment) { using (var db = new FilmFinderDb()) { Coment coment = new Coment(); var user = db.Users.First(i => i.Name == _currentUser.Login); var film = db.Films.First(i => i.Name == filmName); coment.Film = film; coment.User = user; coment.Сommentary = comment; db.Coments.Add(coment); db.SaveChanges(); } }
public bool IsUserOwnerComent(Coment coment, User user) { bool result = false; try { result = comentDB.IsUserOwnerComent(coment, user); } catch (Exception ex) { this.LogError(ex); } return(result); }
public bool InsertComent(Coment coment) { bool result = false; try { result = comentDB.InsertComent(coment); } catch (Exception ex) { this.LogError(ex); } return(result); }
// GET: /Discussion/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Coment coment = await db.comments.FindAsync(id); if (coment == null) { return(HttpNotFound()); } return(View(coment)); }
public async Task <ComentResponse> AddAsync(Coment coment) { try { await _comentRepository.AddAsync(coment); await _unitOfWork.CompleteAsync(); return(new ComentResponse(coment)); } catch (Exception ex) { return(new ComentResponse($"An error occurred when saving the coment: {ex.Message}")); } }
public bool IsUserOwnerComent(Coment coment, User user) { DataAccessParameter[] parameters = new DataAccessParameter[2]; parameters[0] = new DataAccessParameter("@ComentId", coment.ComentId, typeof(int), null, ParameterDirection.Input); parameters[1] = new DataAccessParameter("@UserId", user.UserId, typeof(int), null, ParameterDirection.Input); DataTable dt = WikiDBAdapter.GetDataTable("IsUserOwnerComent", parameters); bool result = false; if (dt != null && dt.Rows.Count > 0) { result = true; } return(result); }
public JsonResult AddComent(string id, string text) { int.TryParse(id, out var postId); var post = _uow.Posts.Get(postId); var coment = new Coment { Post = post, Text = text, UserId = post.UserId }; post.Coments.Add(coment); _uow.Posts.Edit(post); _uow.Save(); return(Json(true)); }
public ActionResult Comentar(Coment comentario, int idLibro /*, int idUsuario*/) { //ViewBag.usuario = idUsuario; ViewBag.libro = idLibro; if (ModelState.IsValid) { comentario.LibroId = idLibro; //comentario.UsuarioId = idUsuario; ViewBag.captura = "Comentario Agregado"; context.Comentarios.Add(comentario); context.SaveChanges(); } return(View()); }
public async Task <ActionResult> Create([Bind(Include = "id,text")] Coment coment) { ApplicationUser currentuser = db.Users.Find(User.Identity.GetUserId()); Post p = db.post.Find(post.id); //await manager.FindByIdAsync(User.Identity.GetUserId()); if (ModelState.IsValid) { coment.author = currentuser; coment.post = p; db.comments.Add(coment); await db.SaveChangesAsync(); return(RedirectToAction("Index/" + post.id)); } return(View(coment)); }
public Coment DeleteComent(Coment coment, User user) { try { if (IsUserOwnerComent(coment, user)) { coment.OperationResult = comentDB.DeleteComent(coment); } else { coment.OperationResult = false; coment.OperationMessage = "El usuario no es propietario."; } } catch (Exception ex) { this.LogError(ex); coment.OperationResult = false; coment.OperationMessage = "Ocurrió un error realizando la operación."; } return(coment); }
static void Main(string[] args) { Coment c1 = new Coment("Tenha um bom dai! "); Coment c2 = new Coment("wow isso é incrível"); Post p1 = new Post( DateTime.Parse("05/08/2019 15:11:44"), "viajando para a nova zelandia", "eu vou visitar este país maravilhoso", 12); p1.AddComment(c1); p1.AddComment(c2); Coment d1 = new Coment("Boa noite "); Coment d2 = new Coment("Que a força esteja com você "); Post p2 = new Post( DateTime.Parse("28 / 07 / 2018 23:14:19"), "Boa noite, galera", "Te vejo amanhã", 15); p2.AddComment(d1); p2.AddComment(d2); Console.WriteLine(p1); Console.WriteLine(p2); }
public ActionResult DeleteComent(int IdComent) { int IdUser = 2; int IdPost = 1; Coment b = db.Coments.Find(IdComent); if (b == null) { return(HttpNotFound()); } db.Coments.Remove(b); db.SaveChanges(); ForPost forPost = new ForPost(); List <Coment> coment = new List <Coment>(); foreach (Coment l in db.Coments.Where(p => p.IdPost == IdPost)) { coment.Add(l); } List <User> userComents = new List <User>(); foreach (Coment l in coment) { foreach (User l2 in db.Users.Where(p => p.IdUser == l.IdUser)) { userComents.Add(l2); } } forPost.Coments = coment; forPost.UserComents = userComents; return(PartialView(forPost)); }
public async Task <ComentResponse> UpdateAsync(string id, Coment coment) { var existingComent = await _comentRepository.GetAsync(id); if (existingComent == null) { return(new ComentResponse("Coment not found.")); } existingComent.Text = coment.Text ?? existingComent.Text; try { _comentRepository.Update(existingComent); await _unitOfWork.CompleteAsync(); return(new ComentResponse(existingComent)); } catch (Exception ex) { return(new ComentResponse($"An error occurred when updating the coment: {ex.Message}")); } }
public ActionResult AddComent(String text) { int IdUser = 2; int IdPost = 1; Coment com = new Coment(); com.IdPost = 1; com.IdUser = 2; com.Text = text; com.user = db.Users.Find(2); db.Entry(com).State = EntityState.Added; db.SaveChanges(); ForPost forPost = new ForPost(); List <Coment> coment = new List <Coment>(); foreach (Coment l in db.Coments.Where(p => p.IdPost == IdPost)) { coment.Add(l); } List <User> userComents = new List <User>(); foreach (Coment l in coment) { foreach (User l2 in db.Users.Where(p => p.IdUser == l.IdUser)) { userComents.Add(l2); } } forPost.Coments = coment; forPost.UserComents = userComents; return(PartialView(forPost)); }
public void addNewRating(double grade, Coment coment) { rating.addNewRating(grade, coment); }
public async Task <IActionResult> CreateComent([FromForm] Coment coment) { return(RedirectToAction("Coment", "Driver", coment.driverId)); }
public Tuple <List <Moment>, List <Users>, List <Coment> > CommentState(string user_id) { OracleConnection conn = new OracleConnection(DBAccess.connStr); try { conn.Open(); } catch (Exception ex) { throw (ex); } OracleCommand cmd = new OracleCommand(); cmd.CommandText = "select * from MOMENT where SENDER_ID ='" + user_id + "' order by TIME desc";//查找该用户的动态 cmd.Connection = conn; OracleDataReader rd = cmd.ExecuteReader(); DateTime CutTime = DateTime.Now.AddDays(-3); List <Moment> moments = new List <Moment>(); List <Users> users = new List <Users>(); List <Coment> comments = new List <Coment>(); Tuple <List <Moment>, List <Users>, List <Coment> > result = new Tuple <List <Moment>, List <Users>, List <Coment> >(null, null, null); if (!rd.HasRows) { return(result); } while (rd.Read())//返回动态详情 { string time = rd["TIME"].ToString(); DateTime send = Convert.ToDateTime(time); if (send > CutTime) { string id = rd["ID"].ToString(); string sender_id = rd["SENDER_ID"].ToString(); string content = rd["CONTENT"].ToString(); int like_num = Convert.ToInt32(rd["LIKE_NUM"]); int forward_num = Convert.ToInt32(rd["FORWARD_NUM"]); int collect_num = Convert.ToInt32(rd["COLLECT_NUM"]); int comment_num = Convert.ToInt32(rd["COMMENT_NUM"]); OracleCommand cmd1 = new OracleCommand(); cmd1.CommandText = "select USER_ID,COMMENT_ID from Publish_Comment where MOMENT_ID ='" + id + "'"; cmd1.Connection = conn; OracleDataReader rd1 = cmd1.ExecuteReader(); while (rd1.Read()) { moments.Add(new Moment(id, sender_id, content, like_num, forward_num, collect_num, comment_num, time)); Users temp = new Users(); Coment ctemp = new Coment(); temp.ID = rd1["USER_ID"].ToString(); ctemp.ID = rd1["COMMENT_ID"].ToString(); OracleCommand cmd2 = new OracleCommand(); cmd2.CommandText = "select * from Users where ID ='" + temp.ID + "'";//返回用户详情 cmd2.Connection = conn; OracleDataReader rd2 = cmd2.ExecuteReader(); rd2.Read(); temp.Email = rd2["EMAIL"].ToString(); temp.Password = rd2["PASSWORD"].ToString(); temp.Username = rd2["USERNAME"].ToString(); temp.Bio = rd2["BIO"].ToString(); temp.Photo = rd2["PHOTO"].ToString(); users.Add(temp); cmd2.CommandText = "select * from Coment where ID ='" + ctemp.ID + "'order by SEND_TIME desc";//返回评论详情 rd2 = cmd2.ExecuteReader(); rd2.Read(); ctemp.Content = rd2["CONTENT"].ToString(); ctemp.SendTime = rd2["SEND_TIME"].ToString(); ctemp.QuoteID = rd2["QUOTE_ID"].ToString(); comments.Add(ctemp); rd2.Close(); } rd1.Close(); } } result = new Tuple <List <Moment>, List <Users>, List <Coment> >(moments, users, comments); rd.Close(); conn.Close(); return(result); }