public async Task <(bool, string)> SendResetPasswordEmail(ApplicationUser currentUser, string url)
        {
            try
            {
                string         subject  = "Reset Password";
                SingleEmailDto emailDto = new SingleEmailDto()
                {
                    ReceiverEmailAddress = currentUser.Email,
                    ReceiverFullName     = currentUser.FullName,
                    HtmlContent          = await sender.FormatEmail(currentUser.FirstName, url)
                };

                if (emailDto.HtmlContent == null)
                {
                    emailDto.HtmlContent = url;
                }
                var res = await sender.SendToSingleEmployee(subject, emailDto);

                if (res == HttpStatusCode.Accepted)
                {
                    return(true, res.ToString());
                }
                else
                {
                    return(false, res.ToString());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public async Task <HttpStatusCode> SendMultipleEmail(string subject, string employeeName, EmailDtoForMultiple emailDtos, string message, string title)
        {
            try
            {
                var    emails = emailDtos.EmailObjects.Select(x => new EmailAddress(x.ReceiverEmailAddress, x.ReceiverFullName)).ToList();
                string url    = "https://resourceedge.herokuapp.com";

                emails.Add(new EmailAddress("[email protected] ", "Nwabugwu Akomas"));

                foreach (var item in emails)
                {
                    SingleEmailDto singleEmail = new SingleEmailDto()
                    {
                        PlainTextContent     = emailDtos.PlainTextContent,
                        HtmlContent          = await FormatEmail(employeeName, item.Name, message, title, url),
                        ReceiverEmailAddress = item.Email,
                        ReceiverFullName     = item.Name
                    };

                    if (singleEmail.HtmlContent == null)
                    {
                        singleEmail.HtmlContent = @$ "<p>{employeeName} has added you as a supervisor, kindly login to resourceedge and approve his EPA.</p>";
                    }

                    await dispatcher.SendSingleEmail(subject, singleEmail);
                }
                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <HttpStatusCode> SendSingleEmail(string subject, SingleEmailDto emailDto)
        {
            EmailAddress email = new EmailAddress(emailDto.ReceiverEmailAddress, emailDto.ReceiverFullName);
            var          msg   = MailHelper.CreateSingleEmail(client.From, email, subject, emailDto.PlainTextContent, emailDto.HtmlContent);
            var          ser   = msg.Serialize();

            var res = await client.GridClient.SendEmailAsync(msg);

            return(res.StatusCode);
        }
Exemplo n.º 4
0
        public async Task <UpdateResult> HodApprovalOrReject(ObjectId appraisalResultId, AcceptanceStatus status)
        {
            var filter = Builders <AppraisalResult> .Filter.Eq("Id", appraisalResultId);

            var appraisalResult = Collection.Find(filter).FirstOrDefault();
            var employee        = await resultAreaRepo.GetEmployee(appraisalResult.KeyResultArea.EmployeeId);

            string subject = $"Pending Approval";
            string msg     = $"who is your HOD has completed your appraisal for the key result area {appraisalResult.KeyResultArea.Name}, You are to accept or reject it";
            string title   = "Approval For Approval";
            string url     = "https://resourceedge.herokuapp.com/";

            if (appraisalResult != null)
            {
                appraisalResult.HodAccept = new AcceptanceStatus()
                {
                    IsAccepted = status.IsAccepted.Value
                };

                var newAppraisalResult = appraisalResult.HodApproval(status.Reason);
                var entityToUpdate     = newAppraisalResult.ToBsonDocument();
                var update             = new BsonDocument("$set", entityToUpdate);

                SingleEmailDto emailDto = new SingleEmailDto()
                {
                    ReceiverFullName     = employee.FullName,
                    ReceiverEmailAddress = employee.Email,
                    HtmlContent          = await sender.FormatEmail(appraisalResult.KeyResultArea.HodDetails.Name, employee.FullName, msg, title, url),
                };

                var res = await Collection.UpdateOneAsync(filter, update);

                if (res.MatchedCount > 0)
                {
                    await sender.SendToSingleEmployee(subject, emailDto);
                }
                return(res);
            }
            return(null);
        }
Exemplo n.º 5
0
 public async Task <HttpStatusCode> SendToSingleEmployee(string Subject, SingleEmailDto singleEmail)
 {
     return(await dispatcher.SendSingleEmail(Subject, singleEmail));
 }
Exemplo n.º 6
0
        public async Task <(bool, string)> SubmitAppraisal(int empId, IEnumerable <AppraisalResultForCreationDto> entities)
        {
            var employee = await resultAreaRepo.GetEmployee(entities.FirstOrDefault().myId);

            string title   = "Appraise";
            string msg     = $"has successfully appraised self. Kindly login to the portal and appraise him/her. <br /> Thank you.</p>";
            string url     = "https://resourceedge.herokuapp.com/";
            string subject = "";
            List <SingleEmailDto> emailDto = new List <SingleEmailDto>();
            SingleEmailDto        email    = new SingleEmailDto();

            if (employee != null)
            {
                subject = $"Appraise {employee.FullName}";

                try
                {
                    foreach (var entity in entities)
                    {
                        var keyResultArea = GetOnlyApplicableKeyoutcomesForAppraisal(entity.KeyResultAreaId, empId, entity.KeyOutcomeScore.Select(x => x.KeyOutcomeId.ToString()).ToList()).FirstOrDefault();
                        if (keyResultArea == null)
                        {
                            return(false, "No Key Result Area Found, Invalid Key result area Id");
                        }
                        //var keyResultArea = await resultAreaRepo.QuerySingle(entity.KeyResultAreaId);

                        if (entity.whoami == null)
                        {
                            var myAppraisal = mapper.Map <AppraisalResult>(entity);
                            myAppraisal.NextAppraisee             = "Appraiser";
                            myAppraisal.EmployeeAccept.IsAccepted = true;

                            myAppraisal.KeyResultArea = keyResultArea;
                            var average = myAppraisal.KeyOutcomeScore.Average(x => x.EmployeeScore.Value);
                            myAppraisal.EmployeeCalculation.ScoreTotal         = myAppraisal.KeyOutcomeScore.Sum(x => x.EmployeeScore).Value;
                            myAppraisal.EmployeeCalculation.Average            = average;
                            myAppraisal.EmployeeCalculation.WeightContribution = (average * (Convert.ToDouble(myAppraisal.KeyResultArea.Weight)) / 100);

                            this.InsertResult(myAppraisal);

                            email.ReceiverFullName     = keyResultArea.AppraiserDetails.Name;
                            email.ReceiverEmailAddress = keyResultArea.AppraiserDetails.Email;
                            email.HtmlContent          = await sender.FormatEmail(employee.FullName, keyResultArea.AppraiserDetails.Name, msg, title, url);

                            if (email.HtmlContent == null)
                            {
                                email.HtmlContent = @$ "<b>Dear {myAppraisal.KeyResultArea.AppraiserDetails.Name},</b> <br /> <p>{employee.FullName} has successfully appraised self. Kindly login to the portal and appraise him/her.<br /><br /> Thank you.</p>";
                            }
                            emailDto.Add(email);
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(false, "Oops something went wrong");
                }
                finally
                {
                    var emailDtos = AppraisalResultExtension.FormatEmailForAppraisal(emailDto);

                    if (emailDtos.Any())
                    {
                        emailDtos.ForEach(async e => await sender.SendToSingleEmployee(subject, e));
                    }
                }
            }
            return(true, "Appraisal Submitted Successfull");
        }
Exemplo n.º 7
0
        public async Task <bool> AppraiseEmployee(int empId, IEnumerable <AppraisalResultForCreationDto> entities)
        {
            var employee = await resultAreaRepo.GetEmployee(empId);

            string title   = "Appraised Done";
            string subject = "";
            string msg     = $"has successfully appraised self. Kindly login to the portal and appraise him/her. <br /> Thank you.</p>";
            string url     = "https://resourceedge.herokuapp.com/";
            List <SingleEmailDto> emailDto = new List <SingleEmailDto>();
            SingleEmailDto        email    = new SingleEmailDto();

            if (employee != null)
            {
                try
                {
                    foreach (var entity in entities)
                    {
                        var filter = Builders <AppraisalResult> .Filter.Where(a => a.myId == empId &&
                                                                              a.AppraisalConfigId == entity.AppraisalConfigId &&
                                                                              a.AppraisalCycleId == entity.AppraisalCycleId &&
                                                                              a.KeyResultArea.Id == entity.KeyResultAreaId);

                        var result = Collection.Find(filter).FirstOrDefault();

                        if (result == null)
                        {
                            return(false);
                        }

                        if (entity.whoami == "APPRAISER")
                        {
                            if (result.NextAppraisee == "Hod")
                            {
                                continue;
                            }


                            result.AppraiseeFeedBack = entity.AppraiseeFeedBack;
                            result.NextAppraisee     = "Hod";
                            result.IsAccepted        = true;

                            foreach (var item in entity.KeyOutcomeScore)
                            {
                                if (result.KeyOutcomeScore.Any(a => a.KeyOutcomeId == item.KeyOutcomeId))
                                {
                                    foreach (var item1 in result.KeyOutcomeScore)
                                    {
                                        if (item.KeyOutcomeId == item1.KeyOutcomeId)
                                        {
                                            result.KeyOutcomeScore.FirstOrDefault(x => x.KeyOutcomeId == item1.KeyOutcomeId).AppraisalScore = item.EmployeeScore;
                                        }
                                    }
                                }
                            }

                            var average = result.KeyOutcomeScore.Average(x => x.AppraisalScore.Value);
                            result.AppraiseeCalculation.ScoreTotal         = result.KeyOutcomeScore.Sum(x => x.AppraisalScore.Value);
                            result.AppraiseeCalculation.Average            = average;
                            result.AppraiseeCalculation.WeightContribution = (average * (Convert.ToDouble(result.KeyResultArea.Weight) / 100));


                            if (result.KeyResultArea.HodDetails.EmployeeId == result.KeyResultArea.AppraiserDetails.EmployeeId)
                            {
                                result.HodAccept.IsAccepted = true;
                                result = result.HodApproval("");
                                result.FinalCalculation.ScoreTotal         = result.KeyOutcomeScore.Sum(x => x.AppraisalScore.Value);
                                result.FinalCalculation.Average            = average;
                                result.FinalCalculation.WeightContribution = (average * (Convert.ToDouble(result.KeyResultArea.Weight) / 100));
                            }

                            var entityToUpdate = result.ToBsonDocument();
                            var update         = new BsonDocument("$set", entityToUpdate);
                            Collection.FindOneAndUpdate(filter, update, options: new FindOneAndUpdateOptions <AppraisalResult> {
                                ReturnDocument = ReturnDocument.After
                            });

                            email.ReceiverFullName     = result.KeyResultArea.Name;
                            email.ReceiverEmailAddress = result.KeyResultArea.HodDetails.Email;
                            email.HtmlContent          = await sender.FormatEmail(employee.FullName, result.KeyResultArea.HodDetails.Name, msg, title, url);

                            if (email.HtmlContent == null)
                            {
                                email.HtmlContent = @$ "<b>Dear {result.KeyResultArea.HodDetails.Name},</b> <br /> <br /> <p>{result.KeyResultArea.AppraiserDetails.Name} has successfully appraised {employee.FullName}. Kindly login to the portal and review. <br /><br /> Thank you.</p>";
                            }
                            emailDto.Add(email);
                        }
                        else if (entity.whoami == "HOD")
                        {
                            if (result.NextAppraisee == "Done")
                            {
                                continue;
                            }

                            foreach (var item in entity.KeyOutcomeScore)
                            {
                                if (result.KeyOutcomeScore.Any(a => a.KeyOutcomeId == item.KeyOutcomeId))
                                {
                                    foreach (var item1 in result.KeyOutcomeScore)
                                    {
                                        if (item.KeyOutcomeId == item1.KeyOutcomeId)
                                        {
                                            result.KeyOutcomeScore.FirstOrDefault(x => x.KeyOutcomeId == item1.KeyOutcomeId).HodScore = item.EmployeeScore;
                                        }
                                    }
                                }
                            }

                            result.AppraiseeFeedBack    = entity.AppraiseeFeedBack;
                            result.HodAccept.IsAccepted = true;
                            var average = result.KeyOutcomeScore.Average(x => x.HodScore.Value);
                            result.FinalCalculation.ScoreTotal         = result.KeyOutcomeScore.Sum(x => x.HodScore.Value);
                            result.FinalCalculation.Average            = average;
                            result.FinalCalculation.WeightContribution = (average * (Convert.ToDouble(result.KeyResultArea.Weight)) / 100);

                            var newAppraisalResult = result.HodApproval("");
                            var entityToUpdate     = newAppraisalResult.ToBsonDocument();
                            var update             = new BsonDocument("$set", entityToUpdate);
                            Collection.FindOneAndUpdate(filter, update, options: new FindOneAndUpdateOptions <AppraisalResult> {
                                ReturnDocument = ReturnDocument.After
                            });
                            msg = $"who is your HOD has completed your appraisal for the key result area {result.KeyResultArea.Name}, You are to accept or reject it";

                            email.ReceiverFullName     = employee.FullName;
                            email.ReceiverEmailAddress = employee.Email;
                            email.HtmlContent          = await sender.FormatEmail(result.KeyResultArea.HodDetails.Name, employee.FullName, msg, title, url);

                            if (email.HtmlContent == null)
                            {
                                email.HtmlContent = @$ "<b>Dear {employee.FullName},</b> <br /> <br /> <p>{result.KeyResultArea.AppraiserDetails.Name} has successfully appraised you. Kindly login to the portal and View. <br /> Thank you.</p>";
                            }
                            emailDto.Add(email);
                        }
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
                finally
                {
                    var emailDtos = AppraisalResultExtension.FormatEmailForAppraisal(emailDto);

                    if (emailDtos.Any())
                    {
                        emailDtos.ForEach(async e => await sender.SendToSingleEmployee(subject, e));
                    }
                }
            }

            return(true);
        }