public ActionResult Create(POAFormModel model)
        {
            try
            {
                bool isExist;
                var  poa = AutoMapper.Mapper.Map <BusinessObject.POA>(model.Detail);
                poa.POA_ID       = model.Detail.UserId;
                poa.CREATED_BY   = CurrentUser.USER_ID;
                poa.CREATED_DATE = DateTime.Now;
                poa.IS_ACTIVE    = true;
                if (model.Detail.PoaSKFile != null)
                {
                    int counter = 0;
                    foreach (var sk in model.Detail.PoaSKFile)
                    {
                        if (sk != null)
                        {
                            var poa_sk        = new POA_SK();
                            var filenamecheck = sk.FileName;
                            if (filenamecheck.Contains("\\"))
                            {
                                poa_sk.FILE_NAME = filenamecheck.Split('\\')[filenamecheck.Split('\\').Length - 1];
                            }
                            else
                            {
                                poa_sk.FILE_NAME = sk.FileName;
                            }

                            poa_sk.FILE_PATH = SaveUploadedFile(sk, poa.ID_CARD, counter);
                            poa.POA_SK.Add(poa_sk);
                            counter += 1;
                        }
                    }
                }
                MASTER_DATA_APPROVAL approvalData;
                _masterDataAprovalBLL.MasterDataApprovalValidation((int)Enums.MenuList.POA, CurrentUser.USER_ID,
                                                                   new BusinessObject.POA(), poa, out isExist, out approvalData, true);
                //_poaBll.Save(poa);
                _masterDataAprovalBLL.SendEmailWorkflow(approvalData.APPROVAL_ID);
                AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                AddMessageInfo(ex.Message, Enums.MessageInfoType.Error);
                return(RedirectToAction("Index"));
            }
            //return RedirectToAction("Create");
        }
        public ActionResult Edit(POAFormModel model)
        {
            try
            {
                bool isExist;
                var  poaId = model.Detail.PoaId;
                var  poa   = _poaBll.GetById(poaId);
                if (model.Detail.PoaSKFile != null)
                {
                    int counter = 0;
                    foreach (var sk in model.Detail.PoaSKFile)
                    {
                        if (sk != null)
                        {
                            var poa_sk        = new POA_SK();
                            var filenamecheck = sk.FileName;
                            if (filenamecheck.Contains("\\"))
                            {
                                poa_sk.FILE_NAME = filenamecheck.Split('\\')[filenamecheck.Split('\\').Length - 1];
                            }
                            else
                            {
                                poa_sk.FILE_NAME = sk.FileName;
                            }
                            poa_sk.FILE_PATH = SaveUploadedFile(sk, poa.ID_CARD, counter);
                            poa_sk.POA_ID    = poaId;
                            _poaskbll.Save(poa_sk);
                            counter += 1;
                        }
                    }
                }
                poa.MODIFIED_BY   = CurrentUser.USER_ID;
                poa.MODIFIED_DATE = DateTime.Now;

                // Added: Set Exciser Flag: True or False
                var modelExciser = new PoaExciserViewModel();
                var data         = new Sampoerna.EMS.CustomService.Data.POA_EXCISER();
                modelExciser.POA_ID = poa.POA_ID;

                var ExciserData = _poaExciserService.GetByPoaID(poa.POA_ID);

                if (model.Detail.IsExciser == true) // if checked true
                {
                    if (ExciserData == null)        // if no data with current POA ID
                    {
                        data.POA_ID            = poa.POA_ID;
                        data.IS_ACTIVE_EXCISER = true;
                        _poaExciserService.CreateExciser(data, (int)Enums.MenuList.POA, (int)Enums.ActionType.Created, (int)CurrentUser.UserRole, CurrentUser.USER_ID);
                    }
                    if (ExciserData != null) // if data exist
                    {
                        if (ExciserData.IS_ACTIVE_EXCISER == false)
                        {
                            data.EXCISER_ID        = ExciserData.EXCISER_ID;
                            data.POA_ID            = modelExciser.POA_ID;
                            data.IS_ACTIVE_EXCISER = true;
                            _poaExciserService.SetActive(data, (int)Enums.MenuList.POA, (int)Enums.ActionType.Modified, (int)CurrentUser.UserRole, CurrentUser.USER_ID);
                        }
                    }
                }
                else // if checked false
                {
                    if (ExciserData == null) // if no data with current POA ID, keep create row
                    {
                        data.POA_ID            = poa.POA_ID;
                        data.IS_ACTIVE_EXCISER = false;
                        _poaExciserService.CreateExciser(data, (int)Enums.MenuList.POA, (int)Enums.ActionType.Created, (int)CurrentUser.UserRole, CurrentUser.USER_ID);
                    }
                    if (ExciserData != null) // if data exist
                    {
                        if (ExciserData.IS_ACTIVE_EXCISER == true)
                        {
                            data.EXCISER_ID        = ExciserData.EXCISER_ID;
                            data.POA_ID            = modelExciser.POA_ID;
                            data.IS_ACTIVE_EXCISER = false;
                            _poaExciserService.SetActive(data, (int)Enums.MenuList.POA, (int)Enums.ActionType.Modified, (int)CurrentUser.UserRole, CurrentUser.USER_ID);
                        }
                    }
                }

                var origin = AutoMapper.Mapper.Map <POAViewDetailModel>(poa);
                var newpoa = AutoMapper.Mapper.Map <BusinessObject.POA>(model.Detail);
                newpoa.CREATED_BY    = poa.CREATED_BY;
                newpoa.CREATED_DATE  = poa.CREATED_DATE;
                newpoa.MODIFIED_BY   = CurrentUser.USER_ID;
                newpoa.MODIFIED_DATE = DateTime.Today;
                newpoa.IS_ACTIVE     = poa.IS_ACTIVE;
                MASTER_DATA_APPROVAL approvalData;
                newpoa = _masterDataAprovalBLL.MasterDataApprovalValidation((int)Enums.MenuList.POA, CurrentUser.USER_ID, poa,
                                                                            newpoa, out isExist, out approvalData);
                SetChanges(origin, newpoa);

                _poaBll.Save(newpoa);
                _masterDataAprovalBLL.SendEmailWorkflow(approvalData.APPROVAL_ID);
                AddMessageInfo(Constans.SubmitMessage.Updated, Enums.MessageInfoType.Success);

                return(RedirectToAction("Index"));
            }

            catch (Exception ex)
            {
                AddMessageInfo(ex.Message, Enums.MessageInfoType.Error);
                model.MainMenu    = _mainMenu;
                model.CurrentMenu = PageInfo;
                model.Managers    = model.Detail.Manager == null?GlobalFunctions.GetCreatorList() : GlobalFunctions.GetCreatorList(model.Detail.Manager.USER_ID);

                model.Users = model.Detail.User == null?GlobalFunctions.GetCreatorList() : GlobalFunctions.GetCreatorList(model.Detail.User.USER_ID);

                return(View(model));
            }
        }
Exemple #3
0
 public void Save(POA_SK poaSK)
 {
     _repository.InsertOrUpdate(poaSK);
 }