private static void AddReportToDb(INinjaFactoryData db, JobReport rep)
 {
     Job finishedJob = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();
     finishedJob.IsSuccessfull = rep.Success;
     finishedJob.EndDate = rep.EndDate;
     finishedJob.Ninja.KillCount += rep.KillCount;
     db.SaveChanges();
 }
        private static void AddReportToDb(INinjaFactoryData db, JobReport rep)
        {
            Job finishedJob = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();

            finishedJob.IsSuccessfull    = rep.Success;
            finishedJob.EndDate          = rep.EndDate;
            finishedJob.Ninja.KillCount += rep.KillCount;
            db.SaveChanges();
        }
        private static bool CheckIfReportIsValid(INinjaFactoryData db, JobReport rep)
        {
            var job = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();

            if (job == null)
            {
                throw new ArgumentOutOfRangeException("There is no job with Id '" + rep.Id + "'");
            }

            if (job.IsSuccessfull.HasValue == true)
            {
                throw new ArgumentException("The job with Id '" + rep.Id + "' is already compleated");
            }

            return(true);
        }
        private static ICollection <JobReport> GetAllRecordsInCollection(MongoCollection <BsonDocument> collection)
        {
            var jobs = collection.FindAll();
            List <JobReport> reports = new List <JobReport>();

            foreach (var job in jobs)
            {
                if (!job.Contains("_id") || !job.Contains("Success"))
                {
                    throw new ArgumentException("There is an invalid row in the Mongo Database");
                }

                int jobId = job["_id"].AsInt32;

                bool isSuccessful = job["Success"].AsBoolean;

                JobReport report = new JobReport()
                {
                    Id      = jobId,
                    Success = isSuccessful
                };

                if (job.Contains("EndDate") && job["EndDate"].IsValidDateTime)
                {
                    report.EndDate = job["EndDate"].ToUniversalTime();
                }
                else
                {
                    report.EndDate = DateTime.Now;
                }

                if (job.Contains("KillCount"))
                {
                    report.KillCount = job["KillCount"].AsInt32;
                }

                reports.Add(report);
            }

            return(reports);
        }
 private static void AddNewEntityToCollection(MongoCollection<BsonDocument> collection, JobReport newEntity)
 {
     collection.Insert(newEntity);
 }
        private static ICollection<JobReport> GetAllRecordsInCollection(MongoCollection<BsonDocument> collection)
        {
            var jobs = collection.FindAll();
            List<JobReport> reports = new List<JobReport>();
            foreach (var job in jobs)
            {
                if (!job.Contains("_id") || !job.Contains("Success"))
                {
                    throw new ArgumentException("There is an invalid row in the Mongo Database");
                }

                int jobId = job["_id"].AsInt32;

                bool isSuccessful = job["Success"].AsBoolean;

                JobReport report = new JobReport()
                {
                    Id = jobId,
                    Success = isSuccessful
                };

                if (job.Contains("EndDate") && job["EndDate"].IsValidDateTime)
                {
                    report.EndDate = job["EndDate"].ToUniversalTime();
                }
                else
                {
                    report.EndDate = DateTime.Now;
                }

                if (job.Contains("KillCount"))
                {
                    report.KillCount = job["KillCount"].AsInt32;
                }

                reports.Add(report);
            }

            return reports;
        }
        private static bool CheckIfReportIsValid(INinjaFactoryData db, JobReport rep)
        {
            var job = db.Jobs.Where(j => j.Id == rep.Id).FirstOrDefault();

            if (job == null)
            {
                throw new ArgumentOutOfRangeException("There is no job with Id '" + rep.Id + "'");
            }

            if (job.IsSuccessfull.HasValue == true)
            {
                throw new ArgumentException("The job with Id '" + rep.Id + "' is already compleated");
            }

            return true;
        }
 private static void AddNewEntityToCollection(MongoCollection <BsonDocument> collection, JobReport newEntity)
 {
     collection.Insert(newEntity);
 }