Esempio n. 1
0
        private void UpdateUserRejectMessage(User userT)
        {
            //insert UserMessage
            UserMessage userM = Factory.Create <UserMessage>("UserMessage", ClassType.clsTypeDataModel);

            userM.Message        = "Reject by System after " + WebConfigure.GetApprovalSpvDay() + " days";
            userM.MessageType    = "Auto Reject";
            userM.ToUserId       = userT.UserId;
            userM.CreatedAt      = DateTime.Now;
            userM.ToEmployeeId   = userT.EmployeeId;
            userM.FromEmployeeId = userT.Status == 2 ? userT.Approval1 : userT.Approval2;

            _userMessageBService.Add(userM);
        }
        public ActionResult Approve1Mail(User user, FormCollection collect)
        {
            string token = Common.AccessToken() + user.EmployeeId;

            token = token.Replace("/", "");
            token = token.Replace("+", "");

            var employeeM = _mstEmployeeBService.GetDetail(user.Approval1);

            //next to approval 2
            var userT = _userBService.GetDetail(user.UserId);

            userT.Status        = 3;
            userT.UpdatedAt     = DateTime.Now;
            userT.MobileToken   = token;
            userT.Approval2     = employeeM.Superior_ID;
            userT.NameApproval1 = employeeM.Employee_Name;
            userT.DateApproval1 = DateTime.Now;

            var addDay = Common.NumberOfWorkDays(DateTime.Now, WebConfigure.GetApprovalSpvDay());

            userT.DueDateApproval2 = DateTime.Now.AddDays(addDay);

            userT = _userBService.Edit(userT);


            //insert UserMessage
            UserMessage userM = Factory.Create <UserMessage>("UserMessage", ClassType.clsTypeDataModel);

            userM.Message     = String.IsNullOrWhiteSpace(collect["ApproveMsg"]) ? "" : collect["ApproveMsg"];
            userM.MessageType = "Approve 1";
            userM.ToUserId    = Convert.ToInt32(collect["UserId"]);
            //UserM.FromUserId = Convert.ToInt32(Session["userid"]);
            userM.CreatedAt      = DateTime.Now;
            userM.ToEmployeeId   = userT.EmployeeId;
            userM.FromEmployeeId = userT.Approval1;


            _userMessageBService.Add(userM);

            //Send Email to Approval 1 Status Approve
            Email.SendMailResApp1(userT, userM.Message, 1, 1);

            //Send Email to Approval 2 Need Approve
            Email.SendMailNeedApp2(userT, userM.Message);

            return(RedirectToAction("ApproveList"));
        }
        public ActionResult Create(User user)
        {
            SetListDropdown();

            if (Common.CheckAdmin())
            {
                return(RedirectToAction("Login", "Default"));
            }
            ModelState.Remove("TechnicalJobExperienceDuration");
            ModelState.Remove("TechnicalJobTitle");
            ModelState.Remove("RoleDescription");
            ModelState.Remove("Phone");
            ModelState.Remove("MasterAreaId");
            ModelState.Remove("MasterBranchId");
            if (ModelState.IsValid)
            {
                if (RegisterValidate(user))
                {
                    string token = Common.AccessToken() + user.EmployeeId;

                    var employeeM = _employeeMasterBs.GetDetail(user.EmployeeId);
                    user             = this.ParsingUser(user);
                    user.CreatedAt   = DateTime.Now;
                    user.Status      = 2;
                    token            = token.Replace("/", "");
                    token            = token.Replace("+", "");
                    user.MobileToken = token;
                    user.Approval1   = employeeM.Superior_ID;
                    user.POH_Name    = employeeM.POH_Name;
                    user.Email       = employeeM.Email;
                    if (user.MasterAreaId == 0)
                    {
                        user.AreaName     = null;
                        user.MasterAreaId = 0;
                    }
                    else
                    {
                        user.MasterAreaId = _masterAreaBs.GetDetail(user.MasterAreaId).MasterAreaId;
                        user.AreaName     = _masterAreaBs.GetDetail(user.MasterAreaId).Name;
                    }
                    if (user.MasterBranchId == 0)
                    {
                        user.BranchName     = null;
                        user.MasterBranchId = 0;
                    }
                    else
                    {
                        user.MasterBranchId = _masterBranchBs.GetDetail(user.MasterBranchId).MasterBranchId;
                        user.BranchName     = _masterBranchBs.GetDetail(user.MasterBranchId).Name;
                    }

                    var addDay = Common.NumberOfWorkDays(DateTime.Now, WebConfigure.GetApprovalSpvDay());
                    user.DueDateApproval1 = DateTime.Now.AddDays(addDay);

                    if (Request.Files.Count > 0)
                    {
                        for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                        {
                            var    file     = Request.Files[i];
                            string response = Common.ValidateFileUpload(file);

                            if (response.Equals("true"))
                            {
                                if (file != null)
                                {
                                    var fileName = user.EmployeeId + Path.GetExtension(file.FileName);

                                    var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Upload/UserProfile/"), fileName);
                                    file.SaveAs(path);

                                    user.PhotoProfile = fileName;
                                }
                            }
                        }
                    }

                    var userModel = _userBService.GetByEmployeeId(user.EmployeeId);
                    if (userModel != null && userModel.UserId != 0)
                    {
                        var userModelEdit = _userBService.GetDetail(userModel.UserId);
                        userModelEdit.CreatedAt        = DateTime.Now;
                        userModelEdit.UpdatedAt        = DateTime.Now;
                        userModelEdit.Status           = 2;
                        userModelEdit.Phone            = user.Phone;
                        userModelEdit.MobileToken      = token;
                        userModelEdit.Approval1        = employeeM.Superior_ID;
                        userModelEdit.AreaName         = user.MasterAreaId != 0 ? _masterAreaBs.GetDetail(user.MasterAreaId).Name : null;
                        userModelEdit.BranchName       = user.MasterBranchId != 0 ? _masterBranchBs.GetDetail(user.MasterBranchId).Name : null;
                        userModelEdit.MasterAreaId     = user.MasterAreaId != 0 ? _masterAreaBs.GetDetail(user.MasterAreaId).MasterAreaId : 0;
                        userModelEdit.MasterBranchId   = user.MasterBranchId != 0 ? _masterBranchBs.GetDetail(user.MasterBranchId).MasterBranchId : 0;
                        userModelEdit.RoleId           = user.RoleId;
                        userModelEdit.DueDateApproval1 = user.DueDateApproval1;
                        userModelEdit.RoleDescription  = user.RoleDescription;
                        userModelEdit.TechnicalJobExperienceDuration = user.TechnicalJobExperienceDuration;
                        userModelEdit.TechnicalJobTitle = user.TechnicalJobTitle;
                        _userBService.Edit(userModelEdit);
                    }
                    else
                    {
                        _userBService.Add(user);
                    }
                    Email.SendMailRegister(user);

                    //send email to approval 1 Superior_ID
                    Email.SendMailNeedApp1(user);
                    return(RedirectToAction("Index", "User"));
                }
            }

            return(RedirectToAction("Create", "User"));
        }
#pragma warning disable 1998
        public async Task <ActionResult> Register(User model)
#pragma warning restore 1998
        {
            SetListDropdown();
            ModelState.Remove("TechnicalJobExperienceDuration");
            ModelState.Remove("TechnicalJobTitle");
            ModelState.Remove("RoleDescription");
            ModelState.Remove("Phone");
            ModelState.Remove("MasterAreaId");
            ModelState.Remove("MasterBranchId");
            if (ModelState.IsValid)
            {
                #region cek EmployeeID
                if (RegisterValidate(model))
                {
                    if (_userBService.CheckUserReject(model.EmployeeId))
                    {
                        return(RedirectToAction("Index", "Library"));
                    }
                    //insert User
                    string token = Common.AccessToken() + model.EmployeeId;

                    var employeeM = _mstEmployeeBService.GetDetail(model.EmployeeId);

                    model           = this.ParsingUser(model);
                    model.CreatedAt = DateTime.Now;

                    model.Status = 2;
                    token        = token.Replace("/", "");
                    token        = token.Replace("+", "");

                    model.MobileToken = token;
                    model.Approval1   = employeeM.Superior_ID;

                    if (model.MasterAreaId == 0)
                    {
                        model.AreaName     = null;
                        model.MasterAreaId = 0;
                    }
                    else
                    {
                        model.MasterAreaId = _masterAreaBs.GetDetail(model.MasterAreaId).MasterAreaId;
                        model.AreaName     = _masterAreaBs.GetDetail(model.MasterAreaId).Name;
                    }
                    if (model.MasterBranchId == 0)
                    {
                        model.BranchName     = null;
                        model.MasterBranchId = 0;
                    }
                    else
                    {
                        model.MasterBranchId = _masterBranchBs.GetDetail(model.MasterBranchId).MasterBranchId;
                        model.BranchName     = _masterBranchBs.GetDetail(model.MasterBranchId).Name;
                    }

                    var addDay = Common.NumberOfWorkDays(DateTime.Now, WebConfigure.GetApprovalSpvDay());
                    model.DueDateApproval1 = DateTime.Now.AddDays(addDay);
                    model.POH_Name         = employeeM.POH_Name;

                    var userModel = _userBService.GetByEmployeeId(model.EmployeeId);
                    if (userModel != null)
                    {
                        if (userModel.UserId != 0)
                        {
                            //UserModel = model;
                            var userModelEdit = _userBService.GetDetail(userModel.UserId);
                            //UserModelEdit = this.ParsingUser(model);
                            userModelEdit.CreatedAt        = DateTime.Now;
                            userModelEdit.UpdatedAt        = DateTime.Now;
                            userModelEdit.Status           = 2;
                            userModelEdit.Phone            = model.Phone;
                            userModelEdit.MobileToken      = token;
                            userModelEdit.Approval1        = employeeM.Superior_ID;
                            userModelEdit.AreaName         = model.MasterAreaId != 0 ? _masterAreaBs.GetDetail(model.MasterAreaId).Name : null;
                            userModelEdit.BranchName       = model.MasterBranchId != 0 ? _masterBranchBs.GetDetail(model.MasterBranchId).Name : null;
                            userModelEdit.MasterAreaId     = model.MasterAreaId != 0 ? _masterAreaBs.GetDetail(model.MasterAreaId).MasterAreaId : 0;
                            userModelEdit.MasterBranchId   = model.MasterBranchId != 0 ? _masterBranchBs.GetDetail(model.MasterBranchId).MasterBranchId : 0;
                            userModelEdit.RoleId           = model.RoleId;
                            userModelEdit.DueDateApproval1 = model.DueDateApproval1;
                            userModelEdit.RoleDescription  = model.RoleDescription;
                            userModelEdit.TechnicalJobExperienceDuration = model.TechnicalJobExperienceDuration;
                            userModelEdit.TechnicalJobTitle = model.TechnicalJobTitle;
                            userModelEdit.Email             = _mstEmployeeBService.GetDetail(model.EmployeeId).Email;
                            model = _userBService.Edit(userModelEdit);
                        }
                    }
                    else
                    {
                        model = _userBService.Add(model);
                    }

                    Email.SendMailRegister(model);

                    //send email to approval 1 Superior_ID
                    Email.SendMailNeedApp1(model);

                    return(RedirectToAction("Login", "Account"));
                }
            }
            #endregion
            // If we got this far, something failed, redisplay form
            return(View(model));
        }