Example #1
0
        private void SendNotifReject(SrfRequest Srf, string Notes, string Roles)
        {
            var AppProfile = _userHelper.GetUserProfile(Srf.ApproveOneId.Value);

            if (AppProfile != null)
            {
                var AppUser = _userHelper.GetUser(AppProfile.ApplicationUserId);

                var callbackUrl = Url.Action("Edit",
                                             "Escalation",
                                             new { area = "Admin", id = Srf.Id },
                                             _hostConfiguration.Protocol,
                                             _hostConfiguration.Name);

                _notif.Send(
                    User,                                                             // User From
                    "Service Request Form is rejected by " + Roles + " (Escalation)", // Subject
                    AppProfile.Name,                                                  // User target name
                    AppUser.Email,                                                    // User target email
                    callbackUrl,                                                      // Link CallBack
                    "Service Request Form is rejected by " + Roles + " (Escalation)", // Email content or descriptions
                    Notes,                                                            // Description
                    NotificationInboxStatus.Reject,                                   // Notif Status
                    Activities.SRF                                                    // Activity Status
                    );
            }
        }
Example #2
0
        private void Srf()
        {
            Data dt = new Data("srf");

            foreach (var row in dt.GetData())
            {
                int  index          = 1;
                var  Data           = (List <String>)row;
                var  Email          = Data[index].ToString(); index += 1;
                var  CreatedAt      = Data[index].ToString(); index += 1;
                var  SrfNumber      = Data[index].ToString(); index += 1;
                var  IsOps          = Data[index].ToString(); index += 1;
                var  SrfLineManager = Data[index].ToString(); index += 1;
                var  SrfHeadOfSL    = Data[index].ToString(); index += 1;
                var  SrfHeadOfOps   = Data[index].ToString(); index += 1;
                var  SrfOrNon       = Data[index].ToString(); index += 1;
                var  SrfHsrc        = Data[index].ToString(); index += 1;
                var  SerCoord       = Data[index].ToString(); index += 1;
                var  DateApprov1    = Data[index].ToString(); index += 1;
                var  DateApprov2    = Data[index].ToString(); index += 1;
                var  DateApprov3    = Data[index].ToString(); index += 1;
                var  DateApprov4    = Data[index].ToString(); index += 1;
                var  DateApprov5    = Data[index].ToString(); index += 1;
                var  DateApprov6    = Data[index].ToString(); index += 1;
                var  SrfStatus      = Data[index].ToString(); index += 1;
                var  SrfBegin       = Data[index].ToString(); index += 1;
                var  SrfEnd         = Data[index].ToString(); index += 1;
                var  RateType       = Data[index].ToString(); index += 1;
                var  ActivityCod    = Data[index].ToString(); index += 1;
                var  SRF_LM         = _userProfile.GetAll().Where(x => Truncate(x.Name) == Truncate(SrfLineManager)).FirstOrDefault();
                var  SRF_HSL        = _userProfile.GetAll().Where(x => Truncate(x.Name) == Truncate(SrfHeadOfSL)).FirstOrDefault();
                var  SRF_OPS        = _userProfile.GetAll().Where(x => Truncate(x.Name) == Truncate(SrfHeadOfOps)).FirstOrDefault();
                var  SRF_NONOPS     = _userProfile.GetAll().Where(x => Truncate(x.Name) == Truncate(SrfHeadOfOps)).FirstOrDefault();
                var  SRF_HOSRC      = _userProfile.GetAll().Where(x => Truncate(x.Name) == Truncate(SrfHsrc)).FirstOrDefault();
                var  SRF_SRCRD      = _userProfile.GetAll().Where(x => Truncate(x.Name) == Truncate(SerCoord)).FirstOrDefault();
                bool WhatOps        = !string.IsNullOrEmpty(SrfHeadOfOps) ? true : false;

                var Candidate = _candidate.GetAll().Where(x => Truncate(x.Email) == Truncate(Email)).FirstOrDefault();
                if (Candidate != null)
                {
                    var Vacancy           = _vacancy.GetById(Candidate.VacancyId);
                    var Network           = _networkNumber.GetById(Vacancy.NetworkId);
                    var Type              = SrfType.New;
                    var AnnualLeave       = MonthDistance(DateTime.Parse(SrfBegin), DateTime.Parse(SrfEnd));
                    var ParentId          = (String)null;
                    var CheckCandidateSrf = _srf.GetAll().Where(x => x.Candidate == Candidate).OrderByDescending(x => x.SrfEnd).FirstOrDefault();
                    if (CheckCandidateSrf != null)
                    {
                        Type        = SrfType.Extension;
                        ParentId    = CheckCandidateSrf.Id.ToString();
                        AnnualLeave = AnnualLeave + CheckCandidateSrf.AnnualLeave;
                    }

                    //# Create NewSrf SRF
                    SrfRequest NewSrf = new SrfRequest();
                    NewSrf.CreatedAt        = !string.IsNullOrEmpty(CreatedAt) ? DateTime.Parse(CreatedAt) : DateTime.MinValue;
                    NewSrf.Number           = SrfNumber;
                    NewSrf.Type             = Type;
                    NewSrf.ApproveStatusOne = SrfApproveStatus.Submitted;
                    if (Truncate(RateType) == Truncate("Normal"))
                    {
                        NewSrf.ApproveStatusTwo = SrfApproveStatus.Approved;
                        if (WhatOps == true)
                        {
                            NewSrf.ApproveStatusThree = SrfApproveStatus.Approved;
                            NewSrf.ApproveStatusFour  = SrfApproveStatus.Waiting;
                        }
                        else
                        {
                            NewSrf.ApproveStatusThree = SrfApproveStatus.Waiting;
                            NewSrf.ApproveStatusFour  = SrfApproveStatus.Approved;
                        }
                        NewSrf.ApproveStatusSix = SrfApproveStatus.Approved;
                    }
                    else
                    {
                        NewSrf.ApproveStatusFive = SrfApproveStatus.Approved;
                    }

                    NewSrf.RequestBy       = SRF_LM.Name;
                    NewSrf.SrfBegin        = !string.IsNullOrEmpty(SrfBegin) ? DateTime.Parse(SrfBegin) : DateTime.MinValue;
                    NewSrf.SrfEnd          = !string.IsNullOrEmpty(SrfEnd) ? DateTime.Parse(SrfEnd) : DateTime.MinValue;
                    NewSrf.ServiceLevel    = Vacancy.OtLevel;
                    NewSrf.isWorkstation   = Vacancy.isLaptop;
                    NewSrf.isCommunication = Vacancy.isUsim;
                    NewSrf.IsHrms          = Vacancy.isHrms;
                    NewSrf.IsOps           = WhatOps;
                    NewSrf.IsManager       = false;

                    if (Truncate(RateType) == Truncate("Normal"))
                    {
                        NewSrf.RateType = Domain.Models.Enum.RateType.Normal;
                    }
                    else
                    {
                        NewSrf.RateType   = Domain.Models.Enum.RateType.SpecialRate;
                        NewSrf.SpectValue = Vacancy.NoarmalRate;
                    }

                    NewSrf.IsExtended       = (Type == SrfType.New) ? false : true;
                    NewSrf.IsLocked         = false;
                    NewSrf.Status           = Domain.Models.Enum.SrfStatus.Done;
                    NewSrf.SpectValue       = 0;
                    NewSrf.IsActive         = false;
                    NewSrf.ServicePackId    = Vacancy.ServicePackId;
                    NewSrf.NetworkId        = Vacancy.NetworkId;
                    NewSrf.CostCenterId     = Vacancy.CostCodeId;
                    NewSrf.LineManagerId    = Vacancy.ApproverOneId.Value;
                    NewSrf.ActivityCode     = _activity.GetAll().Where(x => Truncate(x.Code) == Truncate(ActivityCod)).FirstOrDefault();
                    NewSrf.DepartmentId     = Vacancy.DepartmentId;
                    NewSrf.DepartmentSubId  = Vacancy.DepartmentSubId;
                    NewSrf.ProjectManagerId = Network.ProjectManagerId;
                    NewSrf.ApproveOneBy     = SRF_LM;
                    NewSrf.ApproveTwoBy     = SRF_HSL;
                    if (WhatOps == true)
                    {
                        NewSrf.ApproveThreeBy = SRF_OPS;
                    }
                    else
                    {
                        NewSrf.ApproveFourBy = SRF_NONOPS;
                    }
                    NewSrf.ApproveSixBy = SRF_SRCRD;
                    NewSrf.Candidate    = Candidate;
                    NewSrf.AccountId    = Vacancy.AccountNameId;

                    if (!string.IsNullOrEmpty(ParentId))
                    {
                        NewSrf.ExtendFrom = Guid.Parse(ParentId);
                    }

                    NewSrf.AnnualLeave = AnnualLeave;
                    _srf.Add(NewSrf);

                    if (Truncate(RateType) != Truncate("Normal"))
                    {
                        // # Create Escalasi in NewSrf

                        var Escalation = new SrfEscalationRequest();
                        Escalation.OtLevel            = NewSrf.ServiceLevel;
                        Escalation.IsWorkstation      = NewSrf.isWorkstation;
                        Escalation.IsCommnunication   = NewSrf.isCommunication;
                        Escalation.SparateValue       = Vacancy.NoarmalRate;
                        Escalation.Status             = StatusEscalation.Done;
                        Escalation.ApproveStatusOne   = SrfApproveStatus.Approved;
                        Escalation.ApproveStatusTwo   = SrfApproveStatus.Approved;
                        Escalation.ApproveStatusThree = SrfApproveStatus.Approved;
                        Escalation.ApproveStatusFour  = SrfApproveStatus.Approved;
                        Escalation.Note          = "";
                        Escalation.ServicePackId = NewSrf.ServicePackId;
                        Escalation.SrfRequest    = NewSrf;
                        _escalation.Add(Escalation);
                    }

                    if (NewSrf != null)
                    {
                        Count++;
                        Console.WriteLine(Data[0] + " " + Email + " Srf  with " + SrfNumber + "  from " + SrfBegin + " to " + SrfEnd + "  has been saved ");
                    }
                }
                else
                {
                    Console.WriteLine(Data[0] + " " + Email);
                }
            }

            Console.WriteLine(Count + " Srf record has been saved ");
        }
Example #3
0
        public IActionResult Approval(string CandidateId, bool ApprovalStatus, string ApprovalNotes = null)
        {
            var Candidate = Service.GetById(Guid.Parse(CandidateId));

            var callbackUrl = Url.Action("Details",
                                         "Vacancy",
                                         new { area = "Admin", id = Candidate.VacancyId },
                                         _hostConfiguration.Protocol,
                                         _hostConfiguration.Name);


            if (ApprovalStatus == true)
            {
                if (User.IsInRole("Line Manager") && User.IsInRole("Sourcing"))
                {
                    Candidate.ApproveOneStatus = ApproverStatus.Selected;
                    Candidate.ApproveOneDate   = DateTime.Now;
                    Candidate.ApproveOneNotes  = ApprovalNotes;
                    Candidate.ApproveTwoStatus = ApproverStatus.Completed;
                    Candidate.ApproveTwoeDate  = DateTime.Now;
                    Candidate.ApproveTwoNotes  = ApprovalNotes;

                    // Update Another Candidate
                    var Temp = Service.GetAll().Where(x => x.VacancyId.Equals(Candidate.VacancyId) && x.Id != Candidate.Id).ToList();
                    foreach (var row in Temp)
                    {
                        var c = Service.GetById(row.Id);
                        c.ApproveTwoStatus = ApproverStatus.Shortlist;
                        Service.Update(c);
                    }
                }
                else if (User.IsInRole("Line Manager"))
                {
                    Candidate.ApproveOneStatus = ApproverStatus.Selected;
                    Candidate.ApproveOneDate   = DateTime.Now;
                    Candidate.ApproveOneNotes  = ApprovalNotes;
                    Service.Update(Candidate);

                    // Send Notif To Sourcing

                    var Vacancy  = _vacancy.GetById(Candidate.VacancyId);
                    var Sourcing = _user.GetById(Vacancy.ApproverTwoId);
                    var SrcUser  = _userService.GetById(Sourcing.ApplicationUserId);

                    _notif.Send(
                        User,                                                                       // User From
                        "Job vacancy CV is approved by " + _userHelper.GetLoginUser(User).Name,     // Subject
                        Sourcing.Name,                                                              // User target name
                        SrcUser.Email,                                                              // User target email
                        callbackUrl,                                                                // Link CallBack
                        "New Job vacancy CV is approved by " + _userHelper.GetLoginUser(User).Name, // Email content or descriptions
                        ApprovalNotes,                                                              // Description
                        NotificationInboxStatus.Approval,                                           // Notif Status
                        Activities.Vacant                                                           // Activity Status
                        );
                }

                else if (User.IsInRole("Sourcing"))
                {
                    Candidate.ApproveTwoStatus = ApproverStatus.Completed;
                    Candidate.ApproveTwoeDate  = DateTime.Now;
                    Candidate.ApproveTwoNotes  = ApprovalNotes;
                    Service.Update(Candidate);

                    // Update Another Candidate
                    var Temp = Service.GetAll().Where(x => x.VacancyId.Equals(Candidate.VacancyId) && x.Id != Candidate.Id).ToList();
                    foreach (var row in Temp)
                    {
                        var c = Service.GetById(row.Id);
                        c.ApproveTwoStatus = ApproverStatus.Shortlist;
                        Service.Update(c);
                    }
                }

                TempData["Approved"] = "OK";
            }
            else
            {
                // Send Correction To Agency
                var Up      = _userHelper.GetUserProfile(Candidate.AgencyId.Value);
                var AppUser = _userHelper.GetUser(Up.ApplicationUserId);

                _notif.Send(
                    User,                           // User From
                    "Correction CV",                // Subject
                    Up.Name,                        // User target name
                    Up.Email,                       // User target email
                    callbackUrl,                    // Link CallBack
                    "Rejected CV",                  // Email content or descriptions
                    ApprovalNotes,                  // Description
                    NotificationInboxStatus.Reject, // Notif Status
                    Activities.Vacant               // Activity Status
                    );

                Candidate.ApproveOneStatus = ApproverStatus.Shortlist;
                Candidate.ApproveTwoStatus = ApproverStatus.Shortlist;
                Candidate.ApproveOneDate   = DateTime.Now;
                Candidate.ApproveOneNotes  = ApprovalNotes;
                Service.Update(Candidate);
            }

            var Success = Service.GetAll().Where(x => x.ApproveTwoStatus == ApproverStatus.Completed && x.VacancyId.Equals(Candidate.VacancyId)).FirstOrDefault();

            if (Success != null)
            {
                var vc = _vacancy.GetById(Candidate.VacancyId);
                vc.VacancyStatus = ApproverStatus.Completed;
                _vacancy.Update(vc);

                var Dp      = _department.GetById(vc.DepartmentId);
                var Network = _network.GetById(vc.NetworkId);

                // SEND TO SRF
                var LineManager = _user.GetById(vc.ApproverOneId);

                SrfRequest Srf = new SrfRequest
                {
                    Type               = SrfType.New,
                    ApproveOneBy       = vc.ApproverOne,
                    CandidateId        = Candidate.Id,
                    CreatedAt          = DateTime.Now,
                    RequestBy          = _userHelper.GetLoginUser(User).Name,
                    ServicePackId      = vc.ServicePackId,
                    ServiceLevel       = vc.OtLevel,
                    isWorkstation      = vc.isLaptop,
                    isCommunication    = vc.isUsim,
                    NetworkId          = vc.NetworkId,
                    IsManager          = vc.isManager,
                    DepartmentId       = vc.DepartmentId,
                    DepartmentSubId    = vc.DepartmentSubId,
                    CostCenterId       = vc.CostCodeId,
                    IsHrms             = vc.isHrms,
                    IsOps              = Dp.OperateOrNon == 1 ? true : false,
                    LineManagerId      = LineManager.Id,
                    Status             = SrfStatus.Waiting,
                    AccountId          = Network.AccountNameId,
                    ApproveStatusOne   = SrfApproveStatus.Waiting, // Line Manager
                    ApproveStatusTwo   = SrfApproveStatus.Waiting, // Head Of Service Line
                    ApproveStatusThree = SrfApproveStatus.Waiting, // Head Of Operation
                    ApproveStatusFour  = SrfApproveStatus.Waiting, // Head Of Non Operation
                    ApproveStatusFive  = SrfApproveStatus.Waiting, // Head Of Sourcing
                    ApproveStatusSix   = SrfApproveStatus.Waiting, // Service Cordinator
                    ProjectManagerId   = Network.ProjectManagerId,
                    SrfBegin           = null,
                    SrfEnd             = null,
                    IsActive           = false,
                    IsLocked           = false,
                    AnnualLeave        = 0
                };
                _srf.Add(Srf);

                // Send Notif To Line Manager

                var LmUser = _userService.GetById(LineManager.ApplicationUserId);
                _notif.Send(
                    User,                                                                   // User From
                    "Job vacancy CV is approved by " + _userHelper.GetLoginUser(User).Name, // Subject
                    LineManager.Name,                                                       // User target name
                    LmUser.Email,                                                           // User target email
                    callbackUrl,                                                            // Link CallBack
                    "Job vacancy CV is approved by " + _userHelper.GetLoginUser(User).Name, // Email content or descriptions
                    ApprovalNotes,                                                          // Description
                    NotificationInboxStatus.Request,                                        // Notif Status
                    Activities.SRF                                                          // Activity Status
                    );

                TempData["Approved"] = "OK";
            }
            else
            {
                var Selected = Service.GetAll().Where(x => x.ApproveOneStatus == ApproverStatus.Selected && x.VacancyId.Equals(Candidate.VacancyId)).Count();
                var vc       = _vacancy.GetById(Candidate.VacancyId);
                if (Selected > 0)
                {
                    vc.VacancyStatus = ApproverStatus.Selected;
                }
                else
                {
                    TempData["Rejected"] = "OK";
                    vc.VacancyStatus     = ApproverStatus.Rejected;
                }
                _vacancy.Update(vc);
            }



            return(RedirectToAction("Details", "Vacancy", new { id = Candidate.VacancyId }));
        }
Example #4
0
        private void UpdateUser(SrfRequest item, string notes, string id, string type)
        {
            #region CreateUser
            var Candidate = _candidate.GetById(item.CandidateId);
            var AppUser   = _userManager.FindByEmailAsync(Candidate.Email).Result;

            var defaultPassword = _config.GetConfig("user.default.password");
            if (AppUser == null)
            {
                // Email not exists
                var user = new ApplicationUser()
                {
                    UserName    = Candidate.Email,
                    Email       = Candidate.Email,
                    UserProfile = new UserProfile()
                    {
                        Name              = Candidate.Name,
                        Email             = Candidate.Email,
                        UserName          = Candidate.Email,
                        IsActive          = true,
                        Roles             = "Contractor",
                        Address           = Candidate.Address,
                        Birthdate         = Candidate.DateOfBirth,
                        Description       = Candidate.Description,
                        Gender            = Candidate.Gender,
                        HomePhoneNumber   = Candidate.HomePhoneNumber,
                        MobilePhoneNumber = Candidate.MobilePhoneNumber,
                        IdNumber          = Candidate.IdNumber,
                        IsBlacklist       = false,
                        IsTerminate       = false
                    }
                };
                var result = _userManager.CreateAsync(user, defaultPassword).Result;
                if (result.Succeeded)
                {
                    List <string> Roles = new List <string> {
                        "Contractor"
                    };
                    result = _userManager.AddToRolesAsync(user, Roles).Result;
                    if (result.Succeeded)
                    {
                        var code        = _userManager.GenerateEmailConfirmationTokenAsync(user).Result;
                        var callbackUrl = Url.Action("ConfirmEmail",
                                                     "Account",
                                                     new { userId = user.Id, code = code, area = "" },
                                                     _hostConfiguration.Protocol,
                                                     _hostConfiguration.Name);

                        var additionalData = new Dictionary <string, string>()
                        {
                            { "CallbackUrl", callbackUrl },
                            { "Name", Candidate.Name },
                            { "Email", Candidate.Email },
                            { "Password", defaultPassword }
                        };

                        var subject = "You have been registered, please confirm your account, Leave to be taken cannot compensate";

                        var email = _mailingHelper.CreateEmail(_config.GetConfig("smtp.from.email"),
                                                               Candidate.Email,
                                                               subject,
                                                               "Emails/RegisterUser",
                                                               user,
                                                               additionalData,
                                                               null);

                        // Send Email Confirmation To User
                        var emailResult = _mailingHelper.SendEmail(email).Result;

                        // Update Candidate
                        Candidate.IsCandidate  = false;
                        Candidate.IsContractor = true;
                        Candidate.IsUser       = true;
                        Candidate.Account      = user.UserProfile;
                        _candidate.Update(Candidate);
                        _srf.SetActive(item.Id, Candidate.Id, user.UserProfile.Id);
                    }
                }
            }
            else
            {
                if (item.Type == SrfType.New)
                {
                    // Current email registered
                    var UserProfile = _profileService.GetByUserId(AppUser.Id);
                    var callbackUrl = Url.Action("Index",
                                                 "Home",
                                                 new { area = "Admin" },
                                                 _hostConfiguration.Protocol,
                                                 _hostConfiguration.Name);

                    var additionalData = new Dictionary <string, string>()
                    {
                        { "CallbackUrl", callbackUrl },
                        { "Name", Candidate.Name },
                        { "Email", Candidate.Email },
                        { "Password", defaultPassword }
                    };

                    var subject = "You have been registered, please confirm your account, Leave to be taken cannot compensate";

                    var email = _mailingHelper.CreateEmail(_config.GetConfig("smtp.from.email"),
                                                           Candidate.Email,
                                                           subject,
                                                           "Emails/RegisterUser",
                                                           AppUser,
                                                           additionalData,
                                                           null);

                    // Send Email Confirmation To User
                    var emailResult = _mailingHelper.SendEmail(email).Result;

                    // Update User Profile
                    UserProfile up = _profileService.GetById(UserProfile.Id);
                    up.Name              = Candidate.Name;
                    up.Email             = Candidate.Email;
                    up.UserName          = Candidate.Email;
                    up.IsActive          = true;
                    up.Address           = Candidate.Address;
                    up.Birthdate         = Candidate.DateOfBirth;
                    up.Description       = Candidate.Description;
                    up.Gender            = Candidate.Gender;
                    up.HomePhoneNumber   = Candidate.HomePhoneNumber;
                    up.MobilePhoneNumber = Candidate.MobilePhoneNumber;
                    up.IdNumber          = Candidate.IdNumber;
                    up.IsBlacklist       = false;
                    up.IsTerminate       = false;
                    _profileService.Update(up);

                    // Update Candidate
                    Candidate.IsCandidate  = false;
                    Candidate.IsContractor = true;
                    Candidate.IsUser       = true;
                    Candidate.Account      = UserProfile;
                    _candidate.Update(Candidate);
                    _srf.SetActive(item.Id, Candidate.Id, UserProfile.Id);
                }
                else
                {
                    var UserProfile = _profileService.GetByUserId(AppUser.Id);
                    _srf.SetActive(item.Id, Candidate.Id, UserProfile.Id);
                }
            }

            if (User.IsInRole("Service Coordinator"))
            {
                var Number = _srf.GenerateNumnber();
                item.Number = Number;
            }

            // Update General Srf
            item.NotesFirst           = notes;
            item.Status               = SrfStatus.Waiting;
            item.ApproveStatusSix     = SrfApproveStatus.Approved;
            item.DateApproveStatusSix = DateTime.Now;
            _srf.Update(item);

            // Send Notification To LM
            SendNotif(id, item.ApproveOneId, "Service Request Form is approved (Escalation) by " + _userHelper.GetLoginUser(User).Name + " " + type, "your Service Request Form is approved (Escalation) by " + _userHelper.GetLoginUser(User).Name + " " + type, NotificationInboxStatus.Approval, notes);
            #endregion
        }
Example #5
0
        private void MultiApprove(bool status, SrfRequest item, string notes, string id, string type, int OperateOrNon)
        {
            var Escalation = Service.GetAll().Where(x => x.SrfId.Equals(item.Id)).FirstOrDefault();

            #region MultiUser
            if (status == true)
            {
                var PreofileId   = _userHelper.GetUser(User).UserProfile.Id;
                int SendApproval = 0;
                var Approver     = UserApprover.LineManager;

                #region LineManagerApprove
                if (User.IsInRole("Line Manager") && item.ApproveOneId == PreofileId)
                {
                    if (item.Status == SrfStatus.Waiting)
                    {
                        if (item.ApproveStatusOne == SrfApproveStatus.Waiting ||
                            item.ApproveStatusOne == SrfApproveStatus.Reject ||
                            item.ApproveStatusTwo == SrfApproveStatus.Reject ||
                            item.ApproveStatusThree == SrfApproveStatus.Reject ||
                            item.ApproveStatusFour == SrfApproveStatus.Reject ||
                            item.ApproveStatusFive == SrfApproveStatus.Waiting ||
                            item.ApproveStatusSix == SrfApproveStatus.Reject)
                        {
                            if (OperateOrNon == 1)
                            {
                                // Send To Head Of Service Line
                                item.ApproveStatusOne = SrfApproveStatus.Approved;
                                item.ApproveFourId    = null;
                                item.ApproveTwoId     = item.ApproveTwoId;
                                item.ApproveThreeId   = item.ApproveThreeId;
                                SendApproval          = item.ApproveTwoId.Value;
                            }
                            else
                            {
                                // Send To Non Head Operation
                                item.ApproveStatusOne = SrfApproveStatus.Approved;
                                item.ApproveTwoId     = null;
                                item.ApproveThreeId   = null;
                                item.ApproveFourId    = item.ApproveFourId;
                                SendApproval          = item.ApproveFourId.Value;
                            }
                            item.ApproveStatusOne     = SrfApproveStatus.Approved;
                            item.DateApproveStatusOne = DateTime.Now;

                            if (item.Status == SrfStatus.Waiting)
                            {
                                if (item.ApproveStatusOne == SrfApproveStatus.Waiting ||
                                    item.ApproveStatusOne == SrfApproveStatus.Reject ||
                                    item.ApproveStatusTwo == SrfApproveStatus.Reject ||
                                    item.ApproveStatusThree == SrfApproveStatus.Reject ||
                                    item.ApproveStatusFour == SrfApproveStatus.Reject ||
                                    item.ApproveStatusFive == SrfApproveStatus.Waiting ||
                                    item.ApproveStatusSix == SrfApproveStatus.Reject)
                                {
                                    if (item.Status == SrfStatus.Waiting)
                                    {
                                        int total_day = Extension.MonthDistance(item.SrfBegin.Value, item.SrfEnd.Value);
                                        item.DateApproveStatusOne = DateTime.Now;

                                        if (item.Type == SrfType.Extension)
                                        {
                                            item.AnnualLeave = item.AnnualLeave + (int)total_day;
                                        }
                                        else
                                        {
                                            item.AnnualLeave = (int)total_day;
                                        }


                                        if (item.ApproveStatusTwo == SrfApproveStatus.Reject)
                                        {
                                            item.ApproveStatusTwo = SrfApproveStatus.Waiting;
                                        }

                                        if (item.ApproveStatusThree == SrfApproveStatus.Reject)
                                        {
                                            item.ApproveStatusThree = SrfApproveStatus.Waiting;
                                        }

                                        if (item.ApproveStatusFour == SrfApproveStatus.Reject)
                                        {
                                            item.ApproveStatusFour = SrfApproveStatus.Waiting;
                                        }

                                        if (item.ApproveStatusSix == SrfApproveStatus.Reject)
                                        {
                                            item.ApproveStatusSix = SrfApproveStatus.Waiting;
                                        }
                                        TempData["Success"] = "OK";

                                        #region EscalationApprove
                                        // Update Escalation IF Exists
                                        Escalation.Status = StatusEscalation.Submitted;
                                        Service.Update(Escalation);
                                        #endregion
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion

                #region ServiceLine
                if (User.IsInRole("Head Of Service Line") && OperateOrNon == 1 && item.ApproveTwoId == PreofileId)
                {
                    item.NotesFirst           = notes;
                    item.Status               = SrfStatus.Waiting;
                    item.ApproveStatusTwo     = SrfApproveStatus.Approved;
                    item.DateApproveStatusTwo = DateTime.Now;
                    SendApproval              = item.ApproveThreeId.Value;

                    #region EscalationApprove
                    // Update Escalation IF Exists
                    item.ApproveStatusOne = SrfApproveStatus.Approved;
                    Service.Update(Escalation);
                    #endregion

                    Approver = UserApprover.HeadOfServiceLine;
                }
                #endregion

                #region HeadOfOperation
                if (User.IsInRole("Head Of Operation") && OperateOrNon == 1 && item.ApproveThreeId == PreofileId)
                {
                    item.NotesFirst             = notes;
                    item.Status                 = SrfStatus.Waiting;
                    item.ApproveStatusThree     = SrfApproveStatus.Approved;
                    item.DateApproveStatusThree = DateTime.Now;
                    SendApproval                = item.ApproveSixId.Value;

                    #region EscalationApprove
                    // Update Escalation IF Exists

                    if (Escalation != null)
                    {
                        Escalation.ApproveStatusTwo = SrfApproveStatus.Approved;
                        Service.Update(Escalation);
                    }
                    #endregion
                    Approver = UserApprover.HeadOfOperation;
                }
                #endregion

                #region HeadOfNonOperation
                if (User.IsInRole("Head Of Non Operation") && OperateOrNon == 0 && item.ApproveFourId == PreofileId)
                {
                    item.NotesFirst            = notes;
                    item.Status                = SrfStatus.Waiting;
                    item.ApproveStatusFour     = SrfApproveStatus.Approved;
                    item.DateApproveStatusFour = DateTime.Now;
                    SendApproval               = item.ApproveSixId.Value;

                    #region EscalationApprove
                    // Update Escalation IF Exists
                    Escalation.ApproveStatusTwo = SrfApproveStatus.Approved;
                    Service.Update(Escalation);
                    #endregion
                    Approver = UserApprover.HeadOfNonOperation;
                }
                #endregion

                #region HeadOfSouircing
                if (User.IsInRole("Head Of Sourcing") && item.ApproveFiveId == PreofileId)
                {
                    var Esc = Service.GetAll().Where(x => x.SrfId.Equals(item.Id)).FirstOrDefault();
                    if (Esc != null)
                    {
                        // Update General Srf
                        item.NotesFirst            = notes;
                        item.Status                = SrfStatus.Waiting;
                        item.ApproveStatusFive     = SrfApproveStatus.Approved;
                        item.DateApproveStatusFive = DateTime.Now;
                        SendApproval               = item.ApproveSixId.Value;

                        #region EscalationApprove
                        // Update Escalation IF Exists
                        Esc.ApproveStatusThree = SrfApproveStatus.Approved;
                        Service.Update(Esc);
                        #endregion
                        Approver = UserApprover.HeadOfSourcing;
                    }
                }
                #endregion

                #region ServiceCoordinator
                if (User.IsInRole("Service Coordinator") && item.ApproveSixId == PreofileId)
                {
                    UpdateUser(item, notes, id, type);
                    #region EscalationApprove
                    // Update Escalation IF Exists
                    Escalation.ApproveStatusFour = SrfApproveStatus.Approved;
                    Service.Update(Escalation);
                    #endregion
                    Approver = UserApprover.ServiceCoordinator;
                }
                else
                {
                    if (SendApproval != 0)
                    {
                        // Send Email To Approver
                        var LoginUser = _userHelper.GetLoginUser(User);
                        var Notif     = "( Escalation )";

                        if (Approver == UserApprover.LineManager)
                        {
                            SendNotif(id, SendApproval, "New Service Request Form is Submmited " + Notif + " " + type + " By " + LoginUser.Name, "New Service Request Form is Submmited " + type + " By " + LoginUser.Name, NotificationInboxStatus.Approval, notes);
                        }
                        else
                        {
                            SendNotif(id, SendApproval, "New Service Request Form is Approved  " + Notif + " " + type + " By " + LoginUser.Name, "New Service Request Form is Approved " + type + " By " + LoginUser.Name, NotificationInboxStatus.Approval, notes);
                        }
                        _srf.Update(item);
                    }
                }
                #endregion
            }
            else
            {
                Escalation.ApproveStatusOne   = SrfApproveStatus.Waiting;
                Escalation.ApproveStatusTwo   = SrfApproveStatus.Waiting;
                Escalation.ApproveStatusThree = SrfApproveStatus.Waiting;
                Escalation.ApproveStatusFour  = SrfApproveStatus.Waiting;
                Escalation.Status             = StatusEscalation.Waiting;
                Service.Update(Escalation);
                // Send Email To Approver
                var LoginUser = _userHelper.GetLoginUser(User);
                var Notif     = "( Escalation )";
                SendNotif(id, item.ApproveOneId, "New Service Request Form is Rejected " + Notif + " " + type + " By " + LoginUser.Name, "New Service Request Form is Approved " + type + " By " + LoginUser.Name, NotificationInboxStatus.Reject, notes);
            }
            #endregion
        }