예제 #1
0
        private static void SeedAppraisalConfig(IDbContext dbContext)
        {
            var collection = dbContext.Database.GetCollection <AppraisalConfig>($"{nameof(AppraisalConfig)}s");

            if (!collection.AsQueryable().Any())
            {
                var data = new AppraisalConfig()
                {
                    Name       = $"{DateTime.Now.Year} Appraisal Cycle",
                    Year       = DateTime.Now.Year,
                    TotalCycle = 4,
                    Cycles     = new List <AppraisalCycle>()
                    {
                        new AppraisalCycle()
                        {
                            StartDate = DateTime.Now, StopDate = DateTime.Now
                        },
                        new AppraisalCycle()
                        {
                            StartDate = DateTime.Now, StopDate = DateTime.Now
                        },
                        new AppraisalCycle()
                        {
                            StartDate = DateTime.Now, StopDate = DateTime.Now
                        },
                        new AppraisalCycle()
                        {
                            StartDate = DateTime.Now, StopDate = DateTime.Now
                        }
                    }
                };

                collection.InsertOne(data);
            }
        }
 public bool Insert(AppraisalConfig entity)
 {
     try
     {
         Collection.InsertOne(entity);
         return(true);
     }
     catch (Exception ex)
     {
         logger.LogError("Insert of appraisal configuration failed", ex);
         Console.WriteLine("failed to update  appraisal", ex.Message.ToString());
         return(false);
     }
 }
        public bool ActivateCycle(AppraisalConfig appraisalConfig, ObjectId cycleId)
        {
            try
            {
                var filter = Builders <AppraisalConfig> .Filter.Eq("Id", appraisalConfig.Id);

                if (appraisalConfig != null)
                {
                    var activeCycle = appraisalConfig.Cycles.First(c => c.Id == cycleId);
                    activeCycle.isActive = true;

                    var update = appraisalConfig.ToBsonDocument();
                    Collection.UpdateOne(filter, update);

                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }