Пример #1
0
        public bool PostComment(JobViewModel payload)
        {
            CommentModel model = new CommentModel()
            {
                JobId       = payload.JobId,
                UserName    = payload.UserName,
                CommentText = payload.Comment
            };

            return(repository.Add(Context, model));
        }
Пример #2
0
        public IHttpActionResult PostComment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            comment.LostStuffId = id;
            comment.CreatedAt   = DateTime.Now;
            comment.UpdatedAt   = DateTime.Now;
            repository.Add(comment);

            return(Ok(comment));
        }
Пример #3
0
        public IHttpActionResult PostComment(int id, Comment comment)
        {
            var userData = GetCurrentUser(db);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            comment.LostStuffId = id;
            comment.CreatedAt   = DateTime.Now;
            comment.UpdatedAt   = DateTime.Now;
            comment.UserId      = userData.Id;
            comment.UserName    = userData.UserName;
            repository.Add(comment);

            return(Ok(comment));
        }
Пример #4
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                Comment objComment = new Comment();
                objComment.CommentContent = collection[1].ToString();
                objComment.PostId         = int.Parse(collection[2].ToString());
                objComment.UserId         = int.Parse(collection[3].ToString());
                // TODO: Add insert logic here
                repComments.Add(objComment);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #5
0
 public void Add(Comments comment)
 {
     _repo.Add(comment);
 }
Пример #6
0
        static void Main(string[] args)
        {
            DoMigration();

            while (true)
            {
                Console.WriteLine("1. Добавить статью\n2.Добавить комментарий\n3.Показать новости\n4.Выход");
                Console.Write("Выберите действие: ");

                if (!int.TryParse(Console.ReadLine(), out int action))
                {
                    Console.WriteLine("Ошибка! Введите цифры!");
                }
                else if (action < 0 || action > 5)
                {
                    Console.WriteLine("Не существует такого действия!");
                }

                if (action == 1)
                {
                    var article = InitArticle();

                    using (var articleRepository = new ArticlesRepository(connectionString))
                    {
                        articleRepository.Add(article);

                        Console.WriteLine("Статья успешно добавлена!");
                    }
                }
                else if (action == 2)
                {
                    var comment = InitComment();

                    using (var commentRepository = new CommentsRepository(connectionString))
                    {
                        commentRepository.Add(comment);

                        Console.WriteLine("Коммент успешно добавлен!");
                    }
                }
                else if (action == 3)
                {
                    List <Article> articles;

                    using (var articlesRepository = new ArticlesRepository(connectionString))
                    {
                        articles = articlesRepository.GetAll().ToList();
                    }

                    foreach (var article in articles)
                    {
                        Console.WriteLine($"{article.Name}");
                    }
                }
                else if (action == 4)
                {
                    break;
                }

                Console.ReadLine();
                Console.Clear();
            }
        }
Пример #7
0
 public static bool Create(Comments inst)
 {
     return(CommentsRepository.Add(inst) > 0);
 }
Пример #8
0
        public DoctorsModule()
        {
            #region cshtml
            Get["/Doctor/{Id:int}"] = param =>
            {
                var id = param.Id;

                var model = GetDoctorModel(id);//_doctorsRepository.GetAll().FirstOrDefault(d => d.Id.Equals(id));

                return(View["Doctor", model]);
            };

            Get["/Doctors/{Specialization?All}"]             =
                Get["/Doctors/{Specialization?All}/{City?}"] = param =>
            {
                var model = GetDoctorsModels()
                            .Where(d => (param.Specialization.Value.Equals("All") ||
                                         d.Specialization.Equals(param.Specialization)) &&
                                   (!param.City.HasValue ||
                                    d.City.Equals(param.City))).ToList();

                return(View["DoctorsList", model]);
            };

            Post["/Doctor/{Id:int}"] = param =>
            {
                var form = this.Request.Form;

                var model = GetDoctorsModels()
                            .First(d => d.Id.Equals(param.Id));

                _commentsRepository.Add(new Comment()
                {
                    DoctorId = model.Id,
                    Author   = form.Author,
                    Date     = DateTime.Now,
                    Content  = form.Contetn
                });
                _commentsRepository.Save();
                model.Comments.Add(new CommentModel()
                {
                    Author  = form.Author,
                    Date    = DateTime.Now,
                    Content = form.Contetn
                });

                return("OK!");
            };

            Get["/Doctor/{Id:int}/TimeSlot/{TimeSlotId:int}"] = param =>
            {
                var model = GetDoctorsModels()
                            .First(d => d.Id.Equals(param.Id))
                            .TimeSlots.First(ts => ts.Id.Equals(param.TimeSlotId));

                ViewBag.DoctorId = param.Id;

                return(View["TimeSlot", model]);
            };

            Post["/Doctor/{Id:int}/TimeSlot/{TimeSlotId:int}"] = param =>
            {
                var form = this.Request.Form;

                GetDoctorsModels()
                .First(d => d.Id.Equals(param.Id))
                .TimeSlots.First(ts => ts.Id.Equals(param.TimeSlotId)).Visitor = form.Visitor;

                _timeSlotsRepository.GetAll().First(t => t.Id.Equals(param.TimeSlotId)).Visitor = form.Visitor;
                _timeSlotsRepository.Save();

                return("OK!");
            };
            #endregion

            //JSONs
            #region JSON
            Get["/DoctorJSON/{Id:int}"] = param =>
            {
                var id = param.Id;

                var model = GetDoctorModel(id);

                return(new JavaScriptSerializer().Serialize(model));
            };
            Post["/DoctorJSON/{Id:int}"] = param =>
            {
                var form = this.Request.Form;

                var model = GetDoctorsModels()
                            .First(d => d.Id.Equals(param.Id));

                _commentsRepository.Add(new Comment()
                {
                    DoctorId = model.Id,
                    Author   = form.Author,
                    Date     = DateTime.Now,
                    Content  = form.Content
                });
                _commentsRepository.Save();

                return("OK!");
            };
            Get["/DoctorsJSON/{Specialization?All}"]             =
                Get["/DoctorsJSON/{Specialization?All}/{City?}"] = param =>
            {
                var model = GetDoctorsModels()
                            .Where(d => (param.Specialization.Value.Equals("All") ||
                                         d.Specialization.Equals(param.Specialization)) &&
                                   (!param.City.HasValue ||
                                    d.City.Equals(param.City))).ToList();

                return(model.ToJson());
            };
            Get["/TimeSlotJSON/{id}"] = param =>
            {
                var model = GetTimeSlotModel(param.Id);
                return(new JavaScriptSerializer().Serialize(model));
            };
            Post["/TimeSlotJSON/{id}"] = param =>
            {
                var form = this.Request.Form;

                _timeSlotsRepository.GetAll().First(t => t.Id.Equals(param.id)).Visitor = form.Visitor;
                _timeSlotsRepository.Save();

                return("OK!");
            };
            #endregion

            //XMLs
            #region XML
            Get["/DoctorXML/{Id}"] = param =>
            {
                var id = (int)param.Id;

                var model = GetDoctorsModels().FirstOrDefault(d => d.Id.Equals(id));

                return(model.ToXml());
            };

            Get["/DoctorsXML/{Specialization?All}"]             =
                Get["/DoctorsXML/{Specialization?All}/{City?}"] = param =>
            {
                var model = GetDoctorsModels()
                            .Where(d => (param.Specialization.Value.Equals("All") ||
                                         d.Specialization.Equals(param.Specialization)) &&
                                   (!param.City.HasValue ||
                                    d.City.Equals(param.City))).ToList();

                return(model.ToXml());
            };

            Post["/DoctorXML/{Id:int}/TimeSlot/{TimeSlotId:int}"] = param =>
            {
                string bodyString = GetBodyString(this.Request.Body);

                GetDoctorsModels()
                .First(d => d.Id.Equals(param.Id))
                .TimeSlots.First(ts => ts.Id.Equals(param.TimeSlotId)).Visitor = bodyString;

                _timeSlotsRepository.GetAll().First(t => t.Id.Equals(param.TimeSlotId)).Visitor = bodyString;
                _timeSlotsRepository.Save();

                return("OK!");
            };
            #endregion
        }