public async Task <AppraisalConfig> Update(ObjectId Id, AppraisalCycle entity)
        {
            try
            {
                var filter = Builders <AppraisalConfig> .Filter.Eq("Id", Id);

                var update = Builders <AppraisalConfig> .Update.Set("Cycles", entity);

                var result = await Collection.FindOneAndUpdateAsync(filter, update, options : new FindOneAndUpdateOptions <AppraisalConfig, AppraisalConfig> {
                    ReturnDocument = ReturnDocument.After
                });

                if (result != null)
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                logger.LogError("update of appraisal configuration failed", ex);
                Console.WriteLine("failed to update  appraisal", ex.Message.ToString());
                return(null);
            }
        }
예제 #2
0
        private bool GetApplicableKeyOutcomes(KeyOutcome keyOutcome, AppraisalCycle cycle)
        {
            DateTime parsedDate;
            var      regex       = new Regex("(continuously)|(yearly)|(annually)|(weekly)|(quaterly)|(continuous)|(ongoing)");
            var      passedRegex = regex.IsMatch(keyOutcome.TimeLimit.ToLower());

            if (passedRegex) // not a date object
            {
                return(true);
            }
            var splitedTimelimit = keyOutcome.TimeLimit.Split('/');

            if (splitedTimelimit.Length < 3)
            {
                return(false);
            }
            var dateString = $"{splitedTimelimit[1]}/{splitedTimelimit[0]}/{splitedTimelimit[2]}";
            var isvalid    = DateTime.TryParseExact(dateString, "MM/dd/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal, out parsedDate);

            if (isvalid)
            {
                if (parsedDate <= cycle.StopDate)
                {
                    return(true);
                }
            }
            //unknown timelimit supplied so we return false
            return(false);
        }
예제 #3
0
        public IEnumerable <KeyResultArea> GetAcceptedKRAForAppraisal(int userId, AppraisalCycle configParam, string resultId = null)
        {
            if (resultId != null)
            {
                ObjectId Id = new ObjectId(resultId);
                return(KraCollection.AsQueryable().Where(x => x.EmployeeId == userId && x.Id == Id && x.Approved == true && x.Status.Employee == true && x.Year == DateTime.Now.Year).ToList());
            }

            Func <KeyOutcome, bool> function = (x) => GetApplicableKeyOutcomes(x, configParam);
            var year = DateTime.Now.Year;

            return(KraCollection.AsQueryable().Where(x => x.EmployeeId == userId && x.Approved == true && x.Status.Employee == true && x.Year == year).ToList()
                   .Select(x => new KeyResultArea
            {
                keyOutcomes = x.keyOutcomes.Where(y => GetApplicableKeyOutcomes(y, configParam)),
                EmployeeId = x.EmployeeId,
                AppraiserDetails = x.AppraiserDetails,
                Approved = x.Approved,
                HodDetails = x.HodDetails,
                IsActive = x.IsActive,
                Id = x.Id,
                Name = x.Name,
                Status = x.Status,
                UserId = x.UserId,
                Weight = x.Weight,
                Year = x.Year
            }));
        }
        public bool DeactivateCycle(ObjectId configId, AppraisalCycle cycle)
        {
            try
            {
                var filter = Builders <AppraisalConfig> .Filter.Eq("Id", configId);

                var config = Collection.Find(filter).First();
                if (config != null)
                {
                    var activeCycle = config.Cycles.First(c => c.Id == cycle.Id);
                    activeCycle.isActive = false;

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

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