Example #1
0
        protected override void UpdateData(SrfRequest item, SrfRequestModelForm model)
        {
            var Dept = _department.GetById(model.DepartmentId);
            var Network = _network.GetById(model.NetworkId);
            int total_day = Extension.MonthDistance(model.SrfBegin, model.SrfEnd);
            item.SrfBegin = model.SrfBegin;
            item.SrfEnd = model.SrfEnd;
            item.DepartmentId = model.DepartmentId;
            item.DepartmentSubId = model.DepartmentSubId;
            item.CostCenterId = model.CostCenterId;
            item.AccountId = model.AccountId;
            item.NetworkId = model.NetworkId;
            item.Description = model.Description;
            item.ApproveSixId = model.ApproveSixId;
            item.ServicePackId = model.FormVacancy.ServicePackId;
            item.ServiceLevel = model.FormVacancy.OtLevel;
            item.IsHrms = model.FormVacancy.isHrms;
            item.IsManager = model.FormVacancy.isManager;
            item.Number = model.Number;
            item.Type = model.Type;
            item.ActivityId = model.ActivityId;
            item.ApproveStatusOne = model.ApproveStatusOne;
            item.ApproveStatusTwo = model.ApproveStatusTwo;
            item.ApproveStatusThree = model.ApproveStatusThree;
            item.ApproveStatusFour = model.ApproveStatusFour;
            item.ApproveStatusFive = model.ApproveStatusFive;
            item.ApproveStatusSix = model.ApproveStatusSix;
            item.isWorkstation = model.FormVacancy.isLaptop == 1 ? true : false;
            item.isCommunication = model.FormVacancy.isUsim;
            item.ProjectManagerId = Network.ProjectManagerId;
            item.ApproveOneId = model.ApproveOneId;
            item.Status = model.Status;

            if(model.ApproveTwoId!=0)
            {
                item.ApproveTwoId = model.ApproveTwoId;
            }

            if (model.ApproveThreeId!=0)
            {
                item.ApproveThreeId = model.ApproveThreeId;
            }

            if (model.ApproveFourId !=0)
            {
                item.ApproveFourId = model.ApproveFourId;
            }

            if (model.ApproveFiveId !=0)
            {
                item.ApproveFiveId = model.ApproveFiveId;
            }

            if (model.ApproveSixId!=0)
            {
                item.ApproveSixId = model.ApproveSixId;
            }


            var Esc = _escalation.GetAll().Where(x => x.SrfId.Equals(x.Id)).FirstOrDefault();
            if(Esc!=null)
            {
                Esc.ApproveStatusOne = model.ApproveStatusTwo;
                if(Dept.OperateOrNon == 1)
                {
                    Esc.ApproveStatusTwo = model.ApproveStatusTwo;
                }
                else
                {
                    Esc.ApproveStatusTwo = model.ApproveStatusThree;
                }
                Esc.ApproveStatusThree = model.ApproveStatusFive;
                Esc.ApproveStatusFour = model.ApproveStatusSix;
                _escalation.Update(Esc);
             
            }

            if (model.ExtendFrom!=null)
            {
                item.ExtendFrom = model.ExtendFrom;
                item.IsExtended = true;
            }
            else
            {
                item.ExtendFrom = null;
                item.IsExtended = false;
            }

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

            if (Dept.OperateOrNon == 1)
            {
                // Send To Head Of Service Line
                item.ApproveFourId = null;
                item.ApproveTwoId = model.ApproveTwoId;
                item.ApproveThreeId = model.ApproveThreeId;
            }
            else
            {
                // Send To Non Head Operation
                item.ApproveTwoId = null;
                item.ApproveThreeId = null;
                item.ApproveFourId = model.ApproveFourId;
            }

           
                // Update Vacancy
            var Candidate = _candidate.GetById(item.CandidateId);
            if (Candidate != null)
            {
                var Vacancy = _vacancy.GetById(Candidate.VacancyId);
                var UppdateVacancy = Mapper.Map(model.FormVacancy, Vacancy);
                UppdateVacancy.AccountNameId = item.AccountId.Value;
                UppdateVacancy.CostCodeId = item.CostCenterId;
                UppdateVacancy.DepartmentId = item.DepartmentId;
                UppdateVacancy.DepartmentSubId = item.DepartmentSubId;
                UppdateVacancy.NetworkId = item.NetworkId;
                UppdateVacancy.ApproverOneId = item.ApproveOneId;
                UppdateVacancy.ServicePackId = model.FormVacancy.ServicePackId;
                UppdateVacancy.isLaptop = model.FormVacancy.isLaptop == 1 ? true : false;
                UppdateVacancy.isUsim = model.FormVacancy.isUsim;
                UppdateVacancy.isHrms = model.FormVacancy.isHrms;
                UppdateVacancy.isManager = model.FormVacancy.isManager;
                UppdateVacancy.OtLevel = model.FormVacancy.OtLevel;
                _vacancy.Update(UppdateVacancy);

               
               

                // Set SRF Status

                var UserProfile = _profileService.GetById(Candidate.AccountId);
                if (item.Status == SrfStatus.Done)
                {
                    UserProfile.IsBlacklist = false;
                    UserProfile.IsTerminate = false;
                    UserProfile.IsActive = true;
                    _profileService.Update(UserProfile);
                }

                if (item.Status == SrfStatus.Terminate)
                {
                    UserProfile.IsBlacklist = false;
                    UserProfile.IsTerminate = true;
                    UserProfile.IsActive = false;
                    _profileService.Update(UserProfile);
                }

                if (item.Status == SrfStatus.Blacklist)
                {
                    UserProfile.IsBlacklist = true;
                    UserProfile.IsTerminate = false;
                    UserProfile.IsActive = false;
                    _profileService.Update(UserProfile);
                }

                Candidate.AgencyId = model.AgencyId;
                _candidate.Update(Candidate);


                TempData["Success"] = "OK";
            }
        }
Example #2
0
        public IActionResult Update(ContractorModelForm model)
        {
            var Srf = Service.GetById(model.SrfId);

            if (ModelState.IsValid && Srf != null)
            {
                var Candidate   = _contractor.GetById(Srf.CandidateId);
                var UserProfile = _userProfile.GetById(Candidate.AccountId.Value);

                if (model.IdNumber.Length != 16)
                {
                    TempData["Error"] = "Invalid ID Number / (KTP) " + model.IdNumber + " must be 16 digits and numeric";
                    return(RedirectToAction("Edit", new { id = Srf.Id }));
                }
                //else
                //{
                //    if(UserProfile!=null && User.IsInRole("Administrator"))
                //    {
                //        var CheckNumber = _userProfile.GetAll().Where(x => !string.IsNullOrWhiteSpace(x.IdNumber) && x.IdNumber == model.IdNumber && x.Id != Candidate.AccountId.Value).FirstOrDefault();
                //        if (CheckNumber != null)
                //        {
                //            TempData["Error"] = "Invalid ID Number / (KTP) " + model.IdNumber + " has exists with other resource !!";
                //            return RedirectToAction("Edit", new { id = Srf.Id });
                //        }

                //    }
                //}

                UserProfile.AhId = model.AhID;
                UserProfile.Name = model.ContrctorName;
                UserProfile.MobilePhoneNumber = model.MobilePhoneNumber;
                UserProfile.HomePhoneNumber   = model.HomePhoneNumber;
                UserProfile.IdNumber          = model.IdNumber;
                UserProfile.Email             = model.Email;
                UserProfile.Birthplace        = model.PlaceOfBirth;
                UserProfile.Birthdate         = model.DateOfBirth;
                UserProfile.Address           = model.Address;
                UserProfile.UserName          = model.Username;
                UserProfile.Description       = model.Notes;
                _userProfile.Update(UserProfile);

                Candidate.Name              = model.ContrctorName;
                Candidate.HomeBaseId        = model.HomeBaseId;
                Candidate.HomePhoneNumber   = model.HomePhoneNumber;
                Candidate.MobilePhoneNumber = model.MobilePhoneNumber;
                Candidate.IdNumber          = model.IdNumber;
                Candidate.Email             = model.Email;
                Candidate.Nationality       = model.Nationality;
                Candidate.PlaceOfBirth      = model.PlaceOfBirth;
                Candidate.DateOfBirth       = model.DateOfBirth;
                Candidate.Address           = model.Address;
                Candidate.Gender            = model.Gender;
                Candidate.Martial           = model.Martial;
                Candidate.Email             = model.Email;
                Candidate.Description       = model.Notes;
                _contractor.Update(Candidate);

                // Update Vacancy Status
                var Vacancy = _vacancy.GetById(Candidate.VacancyId);
                Vacancy.ServicePackId = model.ServicePackId;
                Vacancy.ApproverOneId = model.LineManagerId;
                if (model.PricelistType == PackageTypes.A)
                {
                    Vacancy.PackageType = _packageType.GetAll().Where(x => x.Name.Trim().ToLower().Equals("A".Trim().ToLower())).FirstOrDefault();
                }
                else if (model.PricelistType == PackageTypes.B)
                {
                    Vacancy.PackageType = _packageType.GetAll().Where(x => x.Name.Trim().ToLower().Equals("B".Trim().ToLower())).FirstOrDefault();
                }
                else
                {
                    Vacancy.PackageType = _packageType.GetAll().Where(x => x.Name.Trim().ToLower().Equals("FSO".Trim().ToLower())).FirstOrDefault();
                }
                _vacancy.Update(Vacancy);

                // Update SRF
                Srf.Number           = model.SrfNumber;
                Srf.ServicePackId    = model.ServicePackId;
                Srf.SrfBegin         = model.SrfBegin;
                Srf.SrfEnd           = model.SrfEnd;
                Srf.LineManagerId    = model.LineManagerId;
                Srf.ProjectManagerId = model.ProjectManagerId;

                var NewAnnual = (Srf.SrfEnd.Value.Month - Srf.SrfBegin.Value.Month) <= 0 ? 0 : (Srf.SrfEnd.Value.Month - Srf.SrfBegin.Value.Month);
                if (Srf.Type == SrfType.Extension)
                {
                    Srf.AnnualLeave = Srf.AnnualLeave + NewAnnual;
                }
                else
                {
                    Srf.AnnualLeave = NewAnnual;
                }

                Service.Update(Srf);

                // Update ASP NET USERS
                var CurrentUser = _userManager.FindByIdAsync(model.ApplicationUserId).Result;
                CurrentUser.Email    = model.Email;
                CurrentUser.UserName = model.Username;
                var Result = _userManager.UpdateAsync(CurrentUser).Result;

                if (!Result.Succeeded)
                {
                    TempData["Error"] = JsonConvert.SerializeObject(Result.Errors);
                    return(RedirectToAction("Edit", new { id = Srf.Id }));
                }

                if (!string.IsNullOrWhiteSpace(model.Password))
                {
                    var Code          = _userManager.GeneratePasswordResetTokenAsync(CurrentUser).Result;
                    var resetPassword = _userManager.ResetPasswordAsync(CurrentUser, Code, model.Password).Result;

                    if (!resetPassword.Succeeded)
                    {
                        TempData["Error"] = JsonConvert.SerializeObject(resetPassword.Errors);
                        return(RedirectToAction("Edit", new { id = Srf.Id }));
                    }
                }

                TempData["Success"] = "OK";
                return(RedirectToAction("Details", new { id = Srf.Id }));
            }

            return(RedirectToAction("Edit", new { id = Srf.Id }));
        }
Example #3
0
        private void Upload()
        {
            var AllUser       = _userProfile.GetAll().ToList();
            var AllVacancy    = _vacancy.GetAll().ToList();
            var AllCandidate  = _candidate.GetAll().ToList();
            var AllEscalation = _escalation.GetAll().ToList();

            foreach (var row in AllUser)
            {
                String IdNumber = null;
                if (!string.IsNullOrEmpty(row.IdNumber))
                {
                    if (row.IdNumber.Length > 16)
                    {
                        IdNumber = row.IdNumber.Substring(0, 16);
                    }
                    else
                    {
                        IdNumber = row.IdNumber;
                    }
                }
                else
                {
                    Random random = new Random();
                    IdNumber = random.Next(0, 16).ToString();
                }

                var Pro = _userProfile.GetById(row.Id);

                // Upload User Profile
                if (!String.IsNullOrEmpty(row.Photo))
                {
                    var File = System.IO.File.Exists(Source + "/" + row.Photo);
                    if (File == true)
                    {
                        String   src    = Upload("temp", row.Photo);
                        FileInfo info   = new FileInfo(Source + "/" + row.Photo);
                        var      result = new Attachment()
                        {
                            Name     = info.Name,
                            FileType = info.Extension,
                            Type     = Attachment.FILE_TYPE_UPLOAD,
                            Path     = src,
                            Size     = info.Length / 1024
                        };
                        string output = JsonConvert.SerializeObject(result);
                        Pro.Photo = output;
                    }
                }


                Pro.IdNumber = IdNumber;
                _userProfile.Update(Pro);
            }



            // Vacancy

            foreach (var row in AllVacancy)
            {
                List <string> files = new List <string>();
                var           vac   = _vacancy.GetById(row.Id);

                if (!String.IsNullOrEmpty(row.Files))
                {
                    var attach = row.Files.Split(',');
                    if (attach != null)
                    {
                        foreach (var a in attach)
                        {
                            var File = System.IO.File.Exists(Source + "/" + a);
                            if (File == true)
                            {
                                String src = Upload("vacancy", a);
                                files.Add(src);
                            }
                        }
                    }
                }

                if (files != null)
                {
                    vac.Files = JsonConvert.SerializeObject(files);
                    _vacancy.Update(vac);
                }
            }


            // Candidate
            foreach (var row in AllCandidate)
            {
                List <string> files = new List <string>();
                var           can   = _candidate.GetById(row.Id);

                if (!String.IsNullOrEmpty(row.Attachments))
                {
                    var attach = row.Attachments.Split(',');
                    if (attach != null)
                    {
                        foreach (var a in attach)
                        {
                            var File = System.IO.File.Exists(Source + "/" + a);
                            if (File == true)
                            {
                                String src = Upload("candidate", a);
                                files.Add(src);
                            }
                        }
                    }
                }

                if (files != null)
                {
                    can.Attachments = JsonConvert.SerializeObject(files);
                    _candidate.Update(can);
                }
            }


            //Srf Escalation
            foreach (var row in AllEscalation)
            {
                List <string> files = new List <string>();
                var           esc   = _escalation.GetById(row.Id);

                if (!String.IsNullOrEmpty(row.Files))
                {
                    var attach = row.Files.Split(',');
                    if (attach != null)
                    {
                        foreach (var a in attach)
                        {
                            var File = System.IO.File.Exists(Source + "/" + a);
                            if (File == true)
                            {
                                String src = Upload("escalation", a);
                                files.Add(src);
                            }
                        }
                    }
                }

                if (files != null)
                {
                    esc.Files = JsonConvert.SerializeObject(files);
                    _escalation.Update(esc);
                }
            }
        }
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
        }