public IActionResult Add(EscalationModelForm model)
        {
            if (ModelState.IsValid)
            {
                var srf  = Service.GetById(model.SrfId);
                var Dept = _department.GetById(srf.DepartmentId);

                if (srf != null)
                {
                    var item      = Mapper.Map <SrfEscalationRequest>(model);
                    int ProfileId = 0;
                    if (Dept.OperateOrNon == 1)
                    {
                        ProfileId = model.Srf.ApproveTwoId;
                    }
                    else
                    {
                        ProfileId = model.Srf.ApproveFourId;
                    }
                    item.OtLevel          = model.OtLevel;
                    item.IsWorkstation    = model.IsWorkstation;
                    item.IsCommnunication = model.IsCommnunication;
                    item.SparateValue     = model.SparateValue;
                    item.Note             = model.Note;
                    item.ServicePackId    = model.ServicePackId;

                    //nitip
                    item.CustomField1 = model.PackageTypeId?.ToString();
                    item.CustomField2 = model.ServicePackCategoryId?.ToString();

                    if (!string.IsNullOrWhiteSpace(model.Files))
                    {
                        string fileDestination    = "uploads/escalation";
                        var    AttachmentUpload   = model.Files.Split('|');
                        var    listSaveAttachment = new List <string>();
                        if (AttachmentUpload != null)
                        {
                            foreach (var file in AttachmentUpload)
                            {
                                if (!string.IsNullOrWhiteSpace(file))
                                {
                                    string FileName   = Path.GetFileNameWithoutExtension(file).ToSlug();
                                    string MovedFiles = _fileHelper.FileMove(file, fileDestination, FileName, true);
                                    if (!string.IsNullOrEmpty(MovedFiles))
                                    {
                                        listSaveAttachment.Add(MovedFiles);
                                    }
                                }
                            }
                            if (listSaveAttachment != null)
                            {
                                item.Files = JsonConvert.SerializeObject(listSaveAttachment);
                            }
                        }
                    }


                    _escalation.Add(item);


                    // Update Srf General
                    srf.SrfBegin        = model.Srf.SrfBegin;
                    srf.SrfEnd          = model.Srf.SrfEnd;
                    srf.AnnualLeave     = Extension.MonthDistance(model.Srf.SrfBegin, model.Srf.SrfEnd);
                    srf.DepartmentId    = model.Srf.DepartmentId;
                    srf.DepartmentSubId = model.Srf.DepartmentSubId;
                    srf.CostCenterId    = model.Srf.CostCenterId;
                    srf.AccountId       = model.Srf.AccountId;
                    srf.NetworkId       = model.Srf.NetworkId;
                    srf.ApproveFiveId   = model.Srf.ApproveFiveId;
                    srf.ApproveSixId    = model.Srf.ApproveSixId;
                    srf.SpectValue      = model.SparateValue;
                    if (model.SparateValue > 0)
                    {
                        srf.RateType = RateType.SpecialRate;
                    }
                    else
                    {
                        srf.RateType = RateType.Normal;
                    }
                    //srf.RateType = RateType.SpecialRate;
                    Service.Update(srf);

                    // Update Vacancy
                    var Candidate = _candidate.GetById(srf.CandidateId);
                    if (Candidate != null)
                    {
                        var Vacancy = _vacancy.GetById(Candidate.VacancyId);
                        if (Vacancy != null)
                        {
                            Vacancy.AccountNameId   = srf.AccountId.Value;
                            Vacancy.CostCodeId      = srf.CostCenterId;
                            Vacancy.DepartmentId    = srf.DepartmentId;
                            Vacancy.DepartmentSubId = srf.DepartmentSubId;
                            Vacancy.NetworkId       = srf.NetworkId;
                            Vacancy.ApproverOneId   = srf.ApproveOneId;
                            Vacancy.ServicePackId   = srf.ServicePackId;
                            Vacancy.isLaptop        = srf.isWorkstation;
                            Vacancy.isUsim          = srf.isCommunication;
                            Vacancy.isHrms          = srf.IsHrms;
                            Vacancy.OtLevel         = model.OtLevel;
                            _vacancy.Update(Vacancy);
                        }
                    }
                }
            }
            TempData["Saved"] = "OK";
            return(RedirectToAction("Edit", "ContractorDataEscalation", new { id = model.SrfId }));
        }
Ejemplo n.º 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 ");
        }