public ActionResult SaveSaftyItem(VmSaveSafetyItemAdmin saveSafetyItemAdmin)
        {
            var result           = true;
            var blTeamSafetyItem = new BLTeamSafetyItem();

            try
            {
                if (ModelState.IsValid)
                {
                    result = blTeamSafetyItem.UpdateTeamSafetyItemStatusAndComment(new VmTeamSafetyItem
                    {
                        TeamId          = saveSafetyItemAdmin.TeamId,
                        SafetyItemId    = saveSafetyItemAdmin.SafetyItemId,
                        LastComment     = saveSafetyItemAdmin.Comment ?? "",
                        LastContent     = saveSafetyItemAdmin.LastContent ?? "",
                        ItemStatus      = saveSafetyItemAdmin.ItemStatus,
                        Type            = true,
                        UserId          = CurrentUserId,
                        AttachedFileUrl = saveSafetyItemAdmin.AttachedFileUrl,
                    });
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            var jsonData = new
            {
                success = result,
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ESPApproveSaftyItem(int teamId, int itemStatus)
        {
            var result           = true;
            var blTeamSafetyItem = new BLTeamSafetyItem();
            var allowInReview    = false;

            try
            {
                if (ModelState.IsValid)
                {
                    var blTeamMember = new BLTeamMember();
                    if (result)
                    {
                        #region

                        if (itemStatus == 2) // In review
                        {
                            var inReviewTeamSafetyItemList = blTeamSafetyItem.GetApproveAllTeamSafetyIteam(teamId);

                            foreach (var item in inReviewTeamSafetyItemList)
                            {
                                if (item.ItemStatus == 2)
                                {
                                    allowInReview = true;
                                }
                            }
                        }

                        if (itemStatus == 2 && allowInReview == false)
                        {
                            var jsonDataInreview = new
                            {
                                success = result,
                                allowInReview,
                            };

                            return(Json(jsonDataInreview, JsonRequestBehavior.AllowGet));
                        }

                        var blTeam = new BLTeam();
                        if (itemStatus == 3) // approve
                        {
                            var approvalTeamSafetyItemList = blTeamSafetyItem.GetApproveAllTeamSafetyIteam(teamId);

                            foreach (var saveSafetyItemAdmin in approvalTeamSafetyItemList)
                            {
                                blTeamSafetyItem.UpdateTeamSafetyItemStatusAndComment(new VmTeamSafetyItem
                                {
                                    TeamId          = saveSafetyItemAdmin.TeamId,
                                    SafetyItemId    = saveSafetyItemAdmin.SafetyItemId,
                                    LastComment     = saveSafetyItemAdmin.LastComment ?? "",
                                    LastContent     = saveSafetyItemAdmin.LastContent ?? "",
                                    ItemStatus      = 3,
                                    Type            = true,
                                    UserId          = CurrentUserId,
                                    AttachedFileUrl = saveSafetyItemAdmin.AttachedFileUrl,
                                });
                            }
                        }

                        var teamMemberList = blTeamMember.GetTeamMembersByRoles(teamId,
                                                                                new string[]
                        {
                            SystemRoles.Advisor.ToString(),
                            SystemRoles.CoAdvisor.ToString(),
                            SystemRoles.Leader.ToString(),
                            SystemRoles.Student.ToString(),
                        });

                        var title = "ESP# WERC - 2019 – " + teamMemberList.First().TeamName;

                        var emailSubject = "An in review Comment For Your WERC 2019 ESP";

                        var emailBody = "<h1>" + title + "</h1>" +
                                        "You ESP has been reviewed in the WERC Design Contest System. It is included questions, comments and/or requests for changes regarding the safety of your experiment." +
                                        "<br/>" +
                                        "Please login to the WERC Design Contest System and respond to these in an understanding and timely manner." +
                                        "<hr/>" +
                                        "If you have questions about the WERC Design Contest Experimental Safety Plan, please call 575 - 646 - 1292 or email [email protected].";

                        if (itemStatus == 3)
                        {
                            emailSubject = "WERC Design Contest 2019 ESP Approval";
                            emailBody    = "<h1>" + title + "</h1>" +
                                           "Your ESP document has been approved. The final phase of approval will happen at the event when myself, or one of my safety team, " +
                                           "will compare this document with your bench scale setup, including any chemicals and materials have on hand." +
                                           "If you foresee any changes before you arrive at the event, please request a revision to your ESP document so it can be re-approved. " +
                                           "After your bench scale setup is approved, you will be issued a run permit and be allowed to collect any starting water/samples needed for your work. " +
                                           "Please remember that the bench scale area at this event is considered to be a laboratory area.  And, as such, everyone will be required to wear safety glasses, " +
                                           "long pants or leg coverings, and close toe shoes at all times.  Thank you for your understanding with this process." +
                                           "<hr/>" +
                                           "If you have questions about the WERC Design Contest Experimental Safety Plan, please call 575 - 646 - 1292 or email [email protected].";
                        }

                        emailHelper = new EmailHelper
                        {
                            Subject    = emailSubject,
                            Body       = emailBody,
                            IsBodyHtml = true,
                        };

                        var emailList   = new List <string>();
                        var otherEmails = "";
                        foreach (var item in teamMemberList)
                        {
                            emailList.Add(item.Email);
                            otherEmails += item.Email + ", ";
                        }

                        emailHelper.EmailList = emailList.ToArray();

                        emailHelper.Send();


                        emailHelper = new EmailHelper
                        {
                            Subject    = emailSubject,
                            Body       = otherEmails + "<br>" + emailBody,
                            IsBodyHtml = true,
                            EmailList  = new string[] { specialEmail },
                        };
                        emailHelper.Send();

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            var jsonData = new
            {
                success = result,
                allowInReview,
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }