Exemple #1
0
        public static void RemoveCommentaryPermanently(int id)
        {
            Commentary b = context.Commentaries.Find(id);

            context.Commentaries.Remove(b);
            context.SaveChanges();
        }
        public Commentary ToComment(CommentEntity commentEntity)
        {
            User       maker      = usersMapper.ToUser(commentEntity.Maker, new List <TeamEntity>());
            Commentary conversion = new Commentary(commentEntity.Id, commentEntity.Text, maker);

            return(conversion);
        }
Exemple #3
0
        public void GetCommentaryTest()
        {
            match.AddCommentary(commentary1.Object);
            Commentary commentary = match.GetCommentary(commentary1.Object.Id);

            Assert.AreEqual(commentary.Text, commentary1.Object.Text);
        }
Exemple #4
0
        private static bool IsStreetSweeping(ParkingRegulation regulation, ParkingEvent parkingEvent,
                                             GeViolation geViolation, PredixContext context, Customer customer)
        {
            bool isVoilation = false;

            if (parkingEvent.EventType.Equals("PKOUT"))
            {
                using (var innerContext = new PredixContext())
                {
                    var inEvent = innerContext.GeViolations.FirstOrDefault(x =>
                                                                           x.ObjectUid == parkingEvent.Properties.ObjectUid &&
                                                                           x.LocationUid == parkingEvent.LocationUid);
                    if (inEvent?.ParkinTime != null)
                    {
                        inEvent.ParkoutTime      = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.EventOutDateTime =
                            parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.ViolationDuration = (long)parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId)
                                                    .Subtract(inEvent.ParkinTime.Value).TotalMinutes;
                        inEvent.StreetSweeping   = true;
                        inEvent.ModifiedDateTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                        inEvent.IsException      = true;
                        inEvent.UserAction       = "Missed_Violation";
                        innerContext.SaveChanges();
                        return(true);
                    }
                }
                return(false);
            }
            if (parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).TimeOfDay >= regulation.StartTime &&
                parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId).TimeOfDay <= regulation.EndTime)
            {
                Commentary.Print("*** StreetWeeping Violation");

                isVoilation = true;
                geViolation.StreetSweeping = true;
                geViolation.ObjectUid      = parkingEvent.Properties.ObjectUid;
                geViolation.LocationUid    = parkingEvent.LocationUid;
                if (parkingEvent.EventType.Equals("PKIN"))
                {
                    geViolation.EventInDateTime =
                        parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                    geViolation.ParkinTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                }

                if (parkingEvent.EventType.Equals("PKOUT"))
                {
                    geViolation.EventOutDateTime =
                        parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                    geViolation.ParkoutTime = parkingEvent.Timestamp.ToUtcDateTimeOrNull().ToTimeZone(customer.TimezoneId);
                }

                geViolation.RegulationId  = regulation.RegualationId;
                geViolation.ViolationType = regulation.ViolationType;

                context.GeViolations.Add(geViolation);
            }

            return(isVoilation);
        }
 public async Task ValidateEditCommentaryAsync(Commentary comment)
 {
     if (!await CanEditCommentaryAsync(comment))
     {
         throw buildException($"The commentary \"{comment.Id}\" can not be edited by current user");
     }
 }
        public void Delete(int id)
        {
            Commentary commentary = unitOfWork.Get <Commentary>(id);

            unitOfWork.Remove <Commentary>(id);
            unitOfWork.SaveChanges();
        }
Exemple #7
0
        public async Task <Commentary> GetCommentaryIdAsync(int id)
        {
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var sqlCmd = @$ "SELECT * FROM
	                                Commentary
                                WHERE 
	                                PostageId= '{id}'"    ;

                using (var cmd = new SqlCommand(sqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;
                    con.Open();

                    var reader = await cmd
                                 .ExecuteReaderAsync()
                                 .ConfigureAwait(false);


                    while (reader.Read())
                    {
                        var commentary = new Commentary(int.Parse(reader["Id"].ToString()),
                                                        int.Parse(reader["PostageId"].ToString()),
                                                        int.Parse(reader["ClientId"].ToString()),
                                                        reader["Text"].ToString(),
                                                        DateTime.Parse(reader["Creation"].ToString()));
                        return(commentary);
                    }

                    return(default);
Exemple #8
0
 public void dataForCommentaryTest()
 {
     dataForUserTest();
     creationDateTime = new DateTime();
     DateTime.TryParse("1/1/2000", out creationDateTime);
     commentary = new Commentary(creationDateTime, creatorUser, "Comentario");
 }
 public async Task ValidateRestoreCommentaryAsync(Commentary comment)
 {
     if (!await CanRestoreCommentaryAsync(comment))
     {
         throw buildException();
     }
 }
        private bool IsUserAuthorizedToEditComment(Commentary comment)
        {
            bool isAdmin  = this.User.IsInRole("Admin");
            bool isAuthor = comment.IsAuthorOfComment(this.User.Identity.Name);

            return(isAdmin || isAuthor);
        }
Exemple #11
0
        public async Task <ServiceResult <CommentThreadError> > CommentThreadAsync(int threadId, string content, string authorNickname)
        {
            if (string.IsNullOrWhiteSpace(content))
            {
                return(ServiceResult.CreateFailed(CommentThreadError.InvalidContent));
            }

            var threadsRepository = _unitOfWork.GetRepository <Thread>();
            var thread            = await threadsRepository.GetFirstOrDefaultAsync(t => t.Id == threadId, t => t.Author, t => t.Section);

            var usersRepository = _unitOfWork.UserRepository;
            var author          = await usersRepository.GetFirstOrDefaultAsync(u => u.Username == authorNickname);

            var commentaryRepository = _unitOfWork.GetRepository <Commentary>();
            var newComment           = new Commentary
            {
                Author      = author,
                Thread      = thread,
                CommentTime = DateTime.UtcNow,
                Content     = content
            };

            commentaryRepository.Create(newComment);

            await _unitOfWork.SaveAsync();

            return(ServiceResult <CommentThreadError> .CreateSuccess());
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            lbl.Caption = Chapter == 0 ? $"Introduction to {Book.Title}" : $"{Book.Title} {Chapter}";

            if (Chapter != 0)
            {
                LoadRanges();
            }
            else
            {
                if (!Commentary.Items.Where(x => x.Book == Book.NumberOfBook && x.ChapterBegin == Chapter).Any())
                {
                    var item = new CommentaryItem(Commentary.Session)
                    {
                        Book             = this.Book.NumberOfBook,
                        ChapterBegin     = 0,
                        ChapterEnd       = 0,
                        VerseBegin       = 0,
                        VerseEnd         = 0,
                        Comments         = String.Empty,
                        ParentCommentary = Commentary
                    };
                    item.Save();
                    Commentary.Save();
                    (Commentary.Session as UnitOfWork).CommitChanges();
                }

                LoadRanges();
            }
        }
Exemple #13
0
        public void StartUp()
        {
            testMapper = new CommentMapper();
            UserId identity = new UserId
            {
                Name     = "aName",
                Surname  = "aSurname",
                UserName = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };
            Mock <User> stub = new Mock <User>(identity, true);

            comment       = new Commentary("this is a comment", stub.Object);
            commentEntity = new CommentEntity()
            {
                Id    = 3,
                Text  = "another comment",
                Maker = new UserEntity()
                {
                    Name     = "aName",
                    Surname  = "aSurname",
                    UserName = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                }
            };
        }
Exemple #14
0
        protected override void OnStart(string[] args)
        {
            Commentary.WriteToFile = true;
            Commentary.Print("Hitory Events Service is Started");
            _locationService = new LocationService(GlobalVariables);
            _eventService    = new EventService(GlobalVariables);
            _imageService    = new ImageService(GlobalVariables);
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["SeedData"]))
            {
                Database.SetInitializer(new MigrateDatabaseToLatestVersion <PredixContext, PredixContextInitializer>());
            }
            _schedular = new Timer(SchedularCallback);
            //Get the Interval in Minutes from AppSettings.
            int intervalMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["IntervalMinutes"]);
            var scheduledTime   = DateTime.Now.AddMinutes(intervalMinutes);

            if (DateTime.Now > scheduledTime)
            {
                //If Scheduled Time is passed set Schedule for the next Interval.
                scheduledTime = scheduledTime.AddMinutes(intervalMinutes);
            }
            TimeSpan timeSpan = scheduledTime.Subtract(DateTime.Now);
            string   schedule =
                $"{timeSpan.Days} day(s) {timeSpan.Hours} hour(s) {timeSpan.Minutes} minute(s) {timeSpan.Seconds} seconds(s)";

            Commentary.Print("Simple Service scheduled to run after: " + schedule + " {0}");
            //Get the difference in Minutes between the Scheduled and Current Time.
            int dueTime = Convert.ToInt32(timeSpan.TotalMilliseconds);

            //Change the Timer's Due Time.
            _schedular.Change(dueTime, Timeout.Infinite);
            //Task.Run(() => GetHistory());
        }
        public void CommentaryGetCreatorUserTest()
        {
            User       creatorUser = new User("Nombre", "Apellido", "Email", birthDate, "Password", teamsUser);
            Commentary commentary  = new Commentary(creationDateTime, creatorUser, "Comentario");

            Assert.AreEqual(commentary.getCreatorUser().getName(), "Nombre");
        }
        public void CommentarySetCommentaryTest()
        {
            Commentary commentary = new Commentary(creationDateTime, creatorUser, "Comentario");

            commentary.SetCommentary("NewComentario");
            Assert.AreEqual(commentary.getCommentary(), "NewComentario");
        }
        public async Task <IActionResult> CreateCommentary(CommentaryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var relatedBlog = _context.Blogs.FirstOrDefault(x => x.Id == model.BlogId);

            if (relatedBlog == null)
            {
                return(Redirect(pathToHome));
            }


            var commentary = new Commentary()
            {
                Text     = model.Text, Blog = relatedBlog, BlogId = model.BlogId,
                DateTime = DateTime.Now, User = await _userManager.GetUserAsync(User)
            };

            _context.Commentaries.Add(commentary);
            _context.SaveChanges();
            _messageSender.Send(_messageSender.GetType().ToString());
            return(Redirect(pathToBlogs));
        }
        public ActionResult Create(CommentaryViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var database = new BlogDbContext())
                {
                    var authorId = database.Users
                                   .Where(u => u.UserName == this.User.Identity.Name)
                                   .First()
                                   .Id;

                    int points = 0;

                    model.AuthorName = database.Users
                                       .Where(u => u.UserName == this.User.Identity.Name)
                                       .First()
                                       .FullName;

                    var comment = new Commentary(authorId, model.Content, points, model.ArticleId, model.AuthorName);

                    comment.AuhtorId = authorId;

                    database.Commentary.Add(comment);
                    database.SaveChanges();

                    return(RedirectToAction("Details\\" + model.ArticleId, "Article"));
                }
            }

            return(View(model));
        }
Exemple #19
0
        public void Initialize()
        {
            Commentary = new Commentary()
            {
                Id = new Guid(), User = null, Video = null, Content = "Olololo"
            };

            _mockUnitofwork = Substitute.For <IUnitOfWork>();

            _mockUserRepository = Substitute.For <IUserRepository>();
            _mockUserRepository.GetUserById(Arg.Any <string>()).Returns(Task.FromResult(new User()
            {
            }));


            _mockVideoRepository = Substitute.For <IVideoRepository>();
            _mockVideoRepository.GetVideoById(Arg.Any <Guid>()).Returns(Task.FromResult(new Video {
            }));

            _mockCommentaryRepository = Substitute.For <ICommentaryRepository>();
            _mockCommentaryRepository.GetCommentaryById(Arg.Any <Guid>()).Returns(Task.FromResult(Commentary));
            _mockCommentaryRepository.GetCommentariesByVideoId(Arg.Any <Guid>()).Returns(Task.FromResult(new Commentary[] { Commentary } as IEnumerable <Commentary>));

            _mockUnitofwork.VideoRepository.Returns(_mockVideoRepository);
            _mockUnitofwork.UserRepository.Returns(_mockUserRepository);
            _mockUnitofwork.CommentaryRepository.Returns(_mockCommentaryRepository);

            _mapper = new MapperConfiguration(opt =>
            {
                opt.AddProfiles(new Profile[] { new MapperService(null) });
            }).CreateMapper();
        }
Exemple #20
0
        public async Task <IActionResult> OnPostAddCommentaryAsync()
        {
            if (ModelState.IsValid)
            {
                var post = await S.Db.Posts
                           .Include(p => p.ModerationInfo)
                           .FirstOrDefaultAsync(p => p.Id == NewCommentary.PostId);

                await Permissions.ValidateAddCommentaryAsync(post);

                var currentUser = await S.Utilities.GetCurrentUserModelOrThrowAsync();

                var comment = new Commentary(
                    currentUser,
                    DateTime.UtcNow,
                    post,
                    NewCommentary.Body);
                S.Db.Commentaries.Add(comment);
                await S.Repository.AddUserActionAsync(currentUser, new UserAction(ActionType.COMMENTARY_ADDED, comment));

                await S.Db.SaveChangesAsync();

                await S.CacheManager.ResetPostPageCacheAsync(post.Id);

                return(RedirectToPage("/Post", new { id = NewCommentary.PostId }));
            }
            else
            {
                return(Redirect(S.History.GetLastURL()));
            }
        }
Exemple #21
0
 public Commentary CommentOnEncounter(int idMatch, Commentary aComment)
 {
     if (!Exists(idMatch))
     {
         throw new EncounterNotFoundException();
     }
     return(CommentOnExistingMatch(idMatch, aComment));
 }
 public ArmoredBear(IBear bear)
 {
     _decoratedBear = bear;
     Health         = _decoratedBear.Health + 1;
     AttackDamage   = _decoratedBear.AttackDamage;
     _decoratedBear.Commentary.ForEach(x => Commentary.Add(x));
     Commentary.Add("It's a bear, with armor.");
 }
        public void CommentarySetCreatorUserTest()
        {
            Commentary commentary     = new Commentary(creationDateTime, creatorUser, "Comentario");
            User       creatorUserNew = new User("NombreNew", "ApellidoNew", "EmailNew", birthDate, "PasswordNew", teamsUser);

            commentary.setCreatorUser(creatorUserNew);
            Assert.AreEqual(commentary.getCreatorUser(), creatorUserNew);
        }
Exemple #24
0
 public ActionResult New(Commentary Coming)
 {
     if (ModelState.IsValid)
     {
         _uw.CommentaryRep.Add(Coming);
         return(RedirectToAction("Index"));
     }
     return(View(Coming));
 }
        public void CommentarySetCreationDateTest()
        {
            Commentary commentary          = new Commentary(creationDateTime, creatorUser, "Comentario");
            DateTime   creationDateTimeNew = new DateTime();

            DateTime.TryParse("2/1/2000", out creationDateTimeNew);
            commentary.setCreationDate(creationDateTimeNew);
            Assert.AreEqual(commentary.getCreationDate(), creationDateTimeNew);
        }
Exemple #26
0
 public CommentaryDto ToDto(Commentary aCommentary)
 {
     return(new CommentaryDto()
     {
         commentId = aCommentary.Id,
         makerUsername = aCommentary.Maker.UserName,
         text = aCommentary.Text
     });
 }
Exemple #27
0
        public void TestInitialize()
        {
            id   = 1;
            text = "The match was so boring";
            UserId identity = GetIdentity();

            user       = new Mock <User>(identity, true);
            commentary = new Commentary(id, text, user.Object);
        }
Exemple #28
0
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = Message?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (Commentary?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ IsFatal.GetHashCode();
         return(hashCode);
     }
 }
Exemple #29
0
        public ActionResult DeleteConfirmed(int id1, int id2, int id3)
        {
            Commentary commentary = db.Commentaries.Find(id3);

            db.Commentaries.Remove(commentary);
            db.SaveChanges();
            TempData["message"] = "Comentariul a fost sters cu succes";
            return(RedirectToRoute("SubjectsShow", new { id1, id2 }));
        }
Exemple #30
0
        public ActionResult Edit(Commentary newObject)
        {
            if (ModelState.IsValid)
            {
                _uw.CommentaryRep.Update(newObject);
                return(RedirectToAction("Index"));
            }

            return(View(newObject));
        }