private void TransferFormValuesTo(RefPerson person, FormCollection formCollection)
 {
     person.PersonFirstName = formCollection["PersonFirstName"];
     person.PersonLastName  = formCollection["PersonLastName"];
     person.PersonGender    = formCollection["PersonGender"];
     if (!string.IsNullOrEmpty(formCollection["PersonDob"]))
     {
         person.PersonDob = Convert.ToDateTime(formCollection["PersonDob"]);
     }
     else
     {
         person.PersonDob = null;
     }
     person.PersonPob    = formCollection["PersonPob"];
     person.PersonPhone  = formCollection["PersonPhone"];
     person.PersonMobile = formCollection["PersonMobile"];
     person.PersonEmail  = formCollection["PersonEmail"];
     //person.PersonRace = formCollection["PersonRace"];
     person.PersonIdCardType      = formCollection["PersonIdCardType"];
     person.PersonIdCardNo        = formCollection["PersonIdCardNo"];
     person.PersonOccupation      = formCollection["PersonOccupation"];
     person.PersonNationality     = formCollection["PersonNationality"];
     person.PersonMarriedStatus   = formCollection["PersonMarriedStatus"];
     person.PersonReligion        = formCollection["PersonReligion"];
     person.PersonOccupation      = formCollection["PersonOccupation"];
     person.PersonOfficceName     = formCollection["PersonOfficceName"];
     person.PersonOfficceAddress  = formCollection["PersonOfficceAddress"];
     person.PersonOfficceCity     = formCollection["PersonOfficceCity"];
     person.PersonOfficcePhone    = formCollection["PersonOfficcePhone"];
     person.PersonOfficcePostCode = formCollection["PersonOfficcePostCode"];
     person.PersonOfficceFax      = formCollection["PersonOfficceFax"];
     person.PersonLastEdu         = formCollection["PersonLastEdu"];
     person.PersonBloodType       = formCollection["PersonBloodType"];
     person.PersonHobby           = formCollection["PersonHobby"];
 }
Exemple #2
0
        private async Task LoadData(string id)
        {
            progressBar.Visibility = Visibility.Visible;
            try
            {
                IEnumerable <RefPerson> temp = await Task.Run(() => RefPerson.GetAllRefPersons());

                List <RefPerson> refs          = new List <RefPerson>(temp);
                List <String>    selectedrefs  = new List <String>();
                List <String>    tickedreaders = new List <String>();

                //selectedrefs =

                var item = Dynamodb.GetItem(id, MyAWSConfigs.ReaderDBtableName);
                Console.WriteLine("dsdddddddddddddddddddddddd" + item["description"]);
                selectedrefs = item["refList"].AsListOfString();

                foreach (var r in refs)
                {
                    r.isCheckedRef = false;
                }



                //Console.WriteLine();

                for (int i = 0; i < selectedrefs.Count; i++)
                {
                    foreach (var j in refs)
                    {
                        if (j.id == selectedrefs[i])
                        {
                            tickedreaders.Add(j.id);
                            j.isCheckedRef = true;
                        }
                    }
                }



                foreach (var j in refs)
                {
                    //tickedreaders.Add(j.id);
                    Console.WriteLine("\n" + j.isCheckedRef);
                }

                RefDataGrid.ItemsSource = refs;
                RefDataGrid.Items.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                progressBar.Visibility = Visibility.Hidden;
            }
        }
Exemple #3
0
 private void TransferFormValuesTo(RefPerson person, FormCollection formCollection)
 {
     person.PersonFirstName = formCollection["PersonFirstName"];
     person.PersonLastName  = formCollection["PersonLastName"];
     person.PersonGender    = formCollection["PersonGender"];
     person.PersonDob       = string.IsNullOrEmpty(formCollection["PersonDob"]) ? (DateTime?)null : Convert.ToDateTime(formCollection["PersonDob"]);
     person.PersonReligion  = formCollection["PersonReligion"];
     person.PersonRace      = formCollection["PersonRace"];
     person.PersonFirstName = formCollection["PersonFirstName"];
     person.PersonFirstName = formCollection["PersonFirstName"];
 }
        public ActionResult Update(MEmployee viewModel, FormCollection formCollection)
        {
            UpdateNumericData(viewModel, formCollection);

            MEmployee mEmployeeToUpdate = _mEmployeeRepository.Get(viewModel.Id);

            TransferFormValuesTo(mEmployeeToUpdate, viewModel);
            mEmployeeToUpdate.DepartmentId = _mDepartmentRepository.Get(formCollection["DepartmentId"]);
            mEmployeeToUpdate.ModifiedDate = DateTime.Now;
            mEmployeeToUpdate.ModifiedBy   = User.Identity.Name;
            mEmployeeToUpdate.DataStatus   = EnumDataStatus.Updated.ToString();

            RefPerson person = mEmployeeToUpdate.PersonId;

            if (person == null)
            {
                person = new RefPerson();
                TransferFormValuesTo(person, formCollection);
                person.SetAssignedIdTo(Guid.NewGuid().ToString());
                person.CreatedDate = DateTime.Now;
                person.CreatedBy   = User.Identity.Name;
                person.DataStatus  = EnumDataStatus.New.ToString();
                _refPersonRepository.Save(person);

                mEmployeeToUpdate.PersonId = person;
            }
            else
            {
                TransferFormValuesTo(person, formCollection);
                person.ModifiedDate = DateTime.Now;
                person.ModifiedBy   = User.Identity.Name;
                person.DataStatus   = EnumDataStatus.Updated.ToString();
            }


            _mEmployeeRepository.Update(mEmployeeToUpdate);

            try
            {
                _mEmployeeRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mEmployeeRepository.DbContext.RollbackTransaction();

                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
Exemple #5
0
        public ActionResult Insert(MCustomer viewModel, FormCollection formCollection)
        {
            RefAddress address = new RefAddress();

            TransferFormValuesTo(address, formCollection);
            address.SetAssignedIdTo(Guid.NewGuid().ToString());
            address.CreatedDate = DateTime.Now;
            address.CreatedBy   = User.Identity.Name;
            address.DataStatus  = EnumDataStatus.New.ToString();
            _refAddressRepository.Save(address);

            RefPerson person = new RefPerson();

            TransferFormValuesTo(person, formCollection);
            person.SetAssignedIdTo(Guid.NewGuid().ToString());
            person.CreatedDate = DateTime.Now;
            person.CreatedBy   = User.Identity.Name;
            person.DataStatus  = EnumDataStatus.New.ToString();
            _refPersonRepository.Save(person);

            UpdateNumericData(viewModel, formCollection);
            MCustomer mCustomerToInsert = new MCustomer();

            TransferFormValuesTo(mCustomerToInsert, viewModel);
            mCustomerToInsert.SetAssignedIdTo(viewModel.Id);
            mCustomerToInsert.CreatedDate = DateTime.Now;
            mCustomerToInsert.CreatedBy   = User.Identity.Name;
            mCustomerToInsert.DataStatus  = EnumDataStatus.New.ToString();

            mCustomerToInsert.AddressId = address;
            mCustomerToInsert.PersonId  = person;

            _mCustomerRepository.Save(mCustomerToInsert);

            try
            {
                _mCustomerRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mCustomerRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
 private void TransferFormValuesTo(RefPerson person, FormCollection formCollection)
 {
     person.PersonFirstName = formCollection["PersonFirstName"];
     person.PersonLastName  = formCollection["PersonLastName"];
     //person.PersonGender = formCollection["PersonGender"];
     //if (formCollection["PersonDob"] != null)
     //    person.PersonDob = Convert.ToDateTime(formCollection["PersonDob"]);
     //person.PersonPob = formCollection["PersonPob"];
     //person.PersonPhone = formCollection["PersonPhone"];
     //person.PersonMobile = formCollection["PersonMobile"];
     //person.PersonEmail = formCollection["PersonEmail"];
     //person.PersonReligion = formCollection["PersonReligion"];
     //person.PersonRace = formCollection["PersonRace"];
     //person.PersonIdCardType = formCollection["PersonIdCardType"];
     //person.PersonIdCardNo = formCollection["PersonIdCardNo"];
 }
        public ActionResult Insert(MEmployee viewModel, FormCollection formCollection)
        {
            MEmployee  mEmployeeToInsert = new MEmployee();
            RefPerson  person            = new RefPerson();
            RefAddress address           = new RefAddress();

            TransferFormValuesTo(person, formCollection);
            person.SetAssignedIdTo(Guid.NewGuid().ToString());
            person.CreatedDate = DateTime.Now;
            person.CreatedBy   = User.Identity.Name;
            person.DataStatus  = EnumDataStatus.New.ToString();
            _refPersonRepository.Save(person);

            TransferFormValuesTo(address, formCollection);
            address.SetAssignedIdTo(Guid.NewGuid().ToString());
            address.CreatedDate = DateTime.Now;
            address.CreatedBy   = User.Identity.Name;
            address.DataStatus  = EnumDataStatus.New.ToString();
            _refAddressRepository.Save(address);

            TransferFormValuesTo(mEmployeeToInsert, viewModel);
            mEmployeeToInsert.DepartmentId = _mDepartmentRepository.Get(formCollection["DepartmentId"]);
            mEmployeeToInsert.SetAssignedIdTo(viewModel.Id);
            mEmployeeToInsert.CreatedDate = DateTime.Now;
            mEmployeeToInsert.CreatedBy   = User.Identity.Name;
            mEmployeeToInsert.DataStatus  = EnumDataStatus.New.ToString();

            mEmployeeToInsert.PersonId  = person;
            mEmployeeToInsert.AddressId = address;
            _mEmployeeRepository.Save(mEmployeeToInsert);

            try
            {
                _mEmployeeRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mEmployeeRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("Data Karyawan Berhasil Disimpan"));
        }
Exemple #8
0
        public ActionResult Update(MCustomer viewModel, FormCollection formCollection)
        {
            UpdateNumericData(viewModel, formCollection);
            MCustomer mCustomerToUpdate = _mCustomerRepository.Get(viewModel.Id);

            TransferFormValuesTo(mCustomerToUpdate, viewModel);
            mCustomerToUpdate.ModifiedDate = DateTime.Now;
            mCustomerToUpdate.ModifiedBy   = User.Identity.Name;
            mCustomerToUpdate.DataStatus   = EnumDataStatus.Updated.ToString();

            RefAddress address = mCustomerToUpdate.AddressId;

            TransferFormValuesTo(address, formCollection);
            address.ModifiedDate = DateTime.Now;
            address.ModifiedBy   = User.Identity.Name;
            address.DataStatus   = EnumDataStatus.Updated.ToString();

            RefPerson person = mCustomerToUpdate.PersonId;

            TransferFormValuesTo(person, formCollection);
            person.ModifiedDate = DateTime.Now;
            person.ModifiedBy   = User.Identity.Name;
            person.DataStatus   = EnumDataStatus.Updated.ToString();

            _mCustomerRepository.Update(mCustomerToUpdate);

            try
            {
                _mCustomerRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mCustomerRepository.DbContext.RollbackTransaction();

                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
        public ActionResult Update(MCustomer viewModel, FormCollection formCollection)
        {
            MCustomer customer = _mCustomerRepository.Get(viewModel.Id);

            TransferFormValuesTo(customer, viewModel);
            customer.ModifiedDate = DateTime.Now;
            customer.ModifiedBy   = User.Identity.Name;
            customer.DataStatus   = EnumDataStatus.Updated.ToString();

            RefAddress address = customer.AddressId;

            TransferFormValuesTo(address, formCollection);
            customer.ModifiedDate = DateTime.Now;
            customer.ModifiedBy   = User.Identity.Name;
            customer.DataStatus   = EnumDataStatus.Updated.ToString();

            RefPerson person = customer.PersonId;

            TransferFormValuesTo(person, formCollection);
            customer.ModifiedDate = DateTime.Now;
            customer.ModifiedBy   = User.Identity.Name;
            customer.DataStatus   = EnumDataStatus.Updated.ToString();

            _mCustomerRepository.Update(customer);

            try
            {
                _mCustomerRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mCustomerRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
        public static SurveyFormViewModel CreateSurveyFormViewModel(ITLoanSurveyRepository tLoanSurveyRepository, IMEmployeeRepository mEmployeeRepository, IMZoneRepository mZoneRepository, IMPartnerRepository mPartnerRepository, IMDepartmentRepository mDepartmentRepository, string loanSurveyId)
        {
            SurveyFormViewModel viewModel = new SurveyFormViewModel();

            viewModel.CanEditId = true;

            TLoanSurvey loanSurvey = null;
            TLoanUnit   loanUnit   = null;
            RefPerson   person     = new RefPerson();
            RefAddress  address    = new RefAddress();

            if (!string.IsNullOrEmpty(loanSurveyId))
            {
                loanSurvey = tLoanSurveyRepository.Get(loanSurveyId);
                person     = loanSurvey.LoanId.PersonId;
                address    = loanSurvey.LoanId.AddressId;
                if (loanSurvey.LoanId.LoanUnits.Count > 0)
                {
                    loanUnit = loanSurvey.LoanId.LoanUnits[0];
                }
                else
                {
                    loanUnit = new TLoanUnit();
                }

                viewModel.CanEditId = true;
            }
            if (loanSurvey == null)
            {
                TLoan loan = new TLoan();
                loanUnit = new TLoanUnit();
                MCustomer customer = new MCustomer();
                loanSurvey = new TLoanSurvey();
                MZone    zone    = new MZone();
                MPartner partner = new MPartner();

                loanSurvey.LoanId                      = loan;
                loanSurvey.LoanId.CustomerId           = customer;
                loanSurvey.LoanId.CustomerId.PersonId  = person;
                loanSurvey.LoanId.CustomerId.AddressId = address;
                loanSurvey.LoanId.ZoneId               = zone;
                loanSurvey.LoanId.PartnerId            = partner;

                MEmployee emp = new MEmployee();
                loan.SalesmanId  = emp;
                loan.SurveyorId  = emp;
                loan.CollectorId = emp;
                loan.TLSId       = emp;
            }
            viewModel.LoanSurvey = loanSurvey;
            viewModel.LoanUnit   = loanUnit;

            //set asset
            SetAssetCheck(loanSurvey.SurveyNeighborAsset, viewModel);

            //fill gender
            var values = from EnumGender e in Enum.GetValues(typeof(EnumGender))
                         select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.GenderList = new SelectList(values, "Id", "Name", person.PersonGender);

            //get education list
            var edus = from EnumEducation e in Enum.GetValues(typeof(EnumEducation))
                       select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.EducationList = new SelectList(edus, "Id", "Name", person.PersonLastEducation);

            //get married status list
            var merrieds = from EnumMarriedStatus e in Enum.GetValues(typeof(EnumMarriedStatus))
                           select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.MarriedStatusList = new SelectList(merrieds, "Id", "Name", person.PersonMarriedStatus);

            //get religions list
            var religions = from EnumReligion e in Enum.GetValues(typeof(EnumReligion))
                            select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.ReligionList = new SelectList(religions, "Id", "Name", person.PersonReligion);

            //get house owner status list
            var houses = from EnumHouseOwner e in Enum.GetValues(typeof(EnumHouseOwner))
                         select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.HouseOwnerList          = new SelectList(houses, "Id", "Name", address.AddressStatusOwner);
            viewModel.GuarantorHouseOwnerList = new SelectList(houses, "Id", "Name", person.PersonGuarantorHouseOwnerStatus);

            //get neighbor character list
            var neighbors = from EnumNeighborChar e in Enum.GetValues(typeof(EnumNeighborChar))
                            select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.NeighborCharList = new SelectList(neighbors, "Id", "Name", loanSurvey.SurveyNeighbor);

            //get house type list
            var housetypes = from EnumHouseType e in Enum.GetValues(typeof(EnumHouseType))
                             select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.HouseTypeList = new SelectList(housetypes, "Id", "Name", loanSurvey.SurveyHouseType);

            //get known customer list
            var knowcustomers = from EnumKnowCustomer e in Enum.GetValues(typeof(EnumKnowCustomer))
                                select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.KnowCustomerList = new SelectList(knowcustomers, "Id", "Name", loanSurvey.LoanId.LoanIsSalesmanKnownCustomer);

            MEmployee employee = new MEmployee();

            var listSaEmployee = mEmployeeRepository.GetEmployeeByDept(EnumDepartment.SA.ToString());

            listSaEmployee.Insert(0, employee);

            var salesman = from emp in listSaEmployee
                           select new { Id = emp.Id, Name = emp.PersonId != null ? emp.PersonId.PersonName : "-Pilih Salesman-" };

            viewModel.SalesmanList = new SelectList(salesman, "Id", "Id", loanSurvey.LoanId.SalesmanId != null ? loanSurvey.LoanId.SalesmanId.Id : string.Empty);

            var listSuEmployee = mEmployeeRepository.GetEmployeeByDept(EnumDepartment.SU.ToString());

            listSuEmployee.Insert(0, employee);

            var surveyor = from emp in listSuEmployee
                           select new { Id = emp.Id, Name = emp.PersonId != null ? emp.PersonId.PersonName : "-Pilih Surveyor-" };

            viewModel.SurveyorList = new SelectList(surveyor, "Id", "Id", loanSurvey.LoanId.SurveyorId != null ? loanSurvey.LoanId.SurveyorId.Id : string.Empty);

            var listColEmployee = mEmployeeRepository.GetEmployeeByDept(EnumDepartment.COL.ToString());

            listColEmployee.Insert(0, employee);

            var collector = from emp in listColEmployee
                            select new { Id = emp.Id, Name = emp.PersonId != null ? emp.PersonId.PersonName : "-Pilih Kolektor-" };

            viewModel.CollectorList = new SelectList(collector, "Id", "Id", loanSurvey.LoanId.CollectorId != null ? loanSurvey.LoanId.CollectorId.Id : string.Empty);

            var listTlsEmployee = mEmployeeRepository.GetEmployeeByDept(EnumDepartment.TLS.ToString());

            listTlsEmployee.Insert(0, employee);

            var tls = from emp in listTlsEmployee
                      select new { Id = emp.Id, Name = emp.PersonId != null ? emp.PersonId.PersonName : "-Pilih Team Leader-" };

            viewModel.TLSList = new SelectList(tls, "Id", "Id", loanSurvey.LoanId.TLSId != null ? loanSurvey.LoanId.TLSId.Id : string.Empty);

            var   listZone = mZoneRepository.GetAll();
            MZone z        = new MZone();

            z.ZoneName = "-Pilih Wilayah-";
            listZone.Insert(0, z);
            var zones = from zo in listZone
                        select new { Id = zo.Id, Name = zo.ZoneName };

            viewModel.ZoneList = new SelectList(zones, "Id", "Name", loanSurvey.LoanId.ZoneId != null ? loanSurvey.LoanId.ZoneId.Id : string.Empty);

            var      listPartner = mPartnerRepository.GetAll();
            MPartner p           = new MPartner();

            p.PartnerName = "-Pilih Toko-";
            listPartner.Insert(0, p);
            var partners = from prtner in listPartner
                           select new { Id = prtner.Id, Name = prtner.PartnerName };

            viewModel.PartnerList = new SelectList(partners, "Id", "Name", loanSurvey.LoanId.PartnerId != null ? loanSurvey.LoanId.PartnerId.Id : string.Empty);

            const string separator = "|";

            string[] photos = new string[0];//= loanSurvey.LoanId.LoanDesc.Split(separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (!string.IsNullOrEmpty(loanSurvey.LoanId.LoanDesc))
            {
                photos = loanSurvey.LoanId.LoanDesc.Split(separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            }
            viewModel.Photo1 = "~/Content/Images/no_photo104_on.jpg";
            viewModel.Photo2 = "~/Content/Images/no_photo104_on.jpg";
            if (photos.Count() > 0)
            {
                viewModel.Photo1 = photos[0];
            }
            if (photos.Count() > 1)
            {
                viewModel.Photo2 = photos[1];
            }

            return(viewModel);
        }
Exemple #11
0
        public static CRFormViewModel CreateCRFormViewModel(ITLoanRepository tLoanRepository, IMEmployeeRepository mEmployeeRepository, string loanCustomerRequestId)
        {
            CRFormViewModel viewModel = new CRFormViewModel();

            viewModel.CanEditId = true;

            TLoan      loan     = null;
            TLoanUnit  loanUnit = null;
            RefPerson  person   = new RefPerson();
            RefAddress address  = new RefAddress();

            if (!string.IsNullOrEmpty(loanCustomerRequestId))
            {
                loan    = tLoanRepository.Get(loanCustomerRequestId);
                person  = loan.PersonId;
                address = loan.AddressId;
                if (loan.LoanUnits.Count > 0)
                {
                    loanUnit = loan.LoanUnits[0];
                }
                else
                {
                    loanUnit = new TLoanUnit();
                }

                viewModel.CanEditId = false;
            }

            if (loan == null)
            {
                MEmployee emp  = new MEmployee();
                MCustomer cust = new MCustomer();

                loan     = new TLoan();
                loanUnit = new TLoanUnit();

                loan.TLSId                = emp;
                loan.CustomerId           = cust;
                loan.CustomerId.PersonId  = person;
                loan.CustomerId.AddressId = address;
            }

            viewModel.Loan     = loan;
            viewModel.LoanUnit = loanUnit;

            if (loan.LoanAdminFee != null)
            {
                if (loan.LoanAdminFee == 25000)
                {
                    viewModel.LoanAdminFee1 = true;
                }
                else if (loan.LoanAdminFee == 50000)
                {
                    viewModel.LoanAdminFee2 = true;
                }
                else if (loan.LoanAdminFee == 75000)
                {
                    viewModel.LoanAdminFee3 = true;
                }
            }

            if (loan.LoanMateraiFee != null)
            {
                viewModel.LoanMateraiFee = true;
            }

            viewModel.Photo1 = "~/Content/Images/no_photo104_on.jpg";
            viewModel.Photo2 = "~/Content/Images/no_photo104_on.jpg";

            if (!string.IsNullOrEmpty(loan.LoanDesc))
            {
                string   separator = "|";
                string[] photos    = loan.LoanDesc.Split(separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (photos.Count() > 0)
                {
                    viewModel.Photo1 = photos[0];
                }
                if (photos.Count() > 1)
                {
                    viewModel.Photo2 = photos[1];
                }
            }

            MEmployee employee = new MEmployee();

            var listTlsEmployee = mEmployeeRepository.GetEmployeeByDept(EnumDepartment.TLS.ToString());

            listTlsEmployee.Insert(0, employee);

            var tls = from emps in listTlsEmployee
                      select new { Id = emps.Id, Name = emps.PersonId != null ? emps.PersonId.PersonName : "-Pilih Team Leader-" };

            viewModel.TLSList = new SelectList(tls, "Id", "Id", loan.TLSId != null ? loan.TLSId.Id : string.Empty);

            var listSaEmployee = mEmployeeRepository.GetEmployeeByDept(EnumDepartment.SA.ToString());

            listSaEmployee.Insert(0, employee);

            var salesman = from emps in listSaEmployee
                           select new { Id = emps.Id, Name = emps.PersonId != null ? emps.PersonId.PersonName : "-Pilih Salesman-" };

            viewModel.SalesmanList = new SelectList(salesman, "Id", "Id", loan.SalesmanId != null ? loan.SalesmanId.Id : string.Empty);

            var listSuEmployee = mEmployeeRepository.GetEmployeeByDept(EnumDepartment.SU.ToString());

            listSuEmployee.Insert(0, employee);

            var surveyor = from emps in listSuEmployee
                           select new { Id = emps.Id, Name = emps.PersonId != null ? emps.PersonId.PersonName : "-Pilih Surveyor-" };

            viewModel.SurveyorList = new SelectList(surveyor, "Id", "Id", loan.SurveyorId != null ? loan.SurveyorId.Id : string.Empty);

            return(viewModel);
        }
        public static RegistrationFormViewModel CreateRegistrationFormViewModel(IMCustomerRepository mCustomerRepository, string customerId)
        {
            RegistrationFormViewModel viewModel = new RegistrationFormViewModel();

            viewModel.CanEditId = true;


            MCustomer  customer = null;
            RefPerson  person   = new RefPerson();
            RefAddress address  = new RefAddress();

            if (!string.IsNullOrEmpty(customerId))
            {
                customer            = mCustomerRepository.Get(customerId);
                person              = customer.PersonId;
                address             = customer.AddressId;
                viewModel.CanEditId = false;
            }
            if (customer == null)
            {
                customer = new MCustomer();

                customer.PersonId = person;

                customer.AddressId = address;
            }
            viewModel.Customer = customer;

            //fill gender
            var values = from EnumGender e in Enum.GetValues(typeof(EnumGender))
                         select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.GenderList = new SelectList(values, "Id", "Name", person.PersonGender);

            ////get letters to list
            //var letters = from EnumLetterTo e in Enum.GetValues(typeof(EnumLetterTo))
            //              select new { ID = e, Name = CommonHelper.GetStringValue(e) };
            //viewModel.LetterList = new SelectList(letters, "Id", "Name");

            //get education list
            var edus = from EnumEducation e in Enum.GetValues(typeof(EnumEducation))
                       select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.EducationList = new SelectList(edus, "Id", "Name", person.PersonLastEdu);

            //get married status list
            var merrieds = from EnumMarriedStatus e in Enum.GetValues(typeof(EnumMarriedStatus))
                           select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.MarriedStatusList = new SelectList(merrieds, "Id", "Name", person.PersonMarriedStatus);

            //get card type list
            var idcards = from EnumIdCardType e in Enum.GetValues(typeof(EnumIdCardType))
                          select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.IdCardTypeList = new SelectList(idcards, "Id", "Name", person.PersonIdCardType);

            //get card type list
            var bloods = from EnumBloodType e in Enum.GetValues(typeof(EnumBloodType))
                         select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.BloodTypeList = new SelectList(bloods, "Id", "Name", person.PersonBloodType);

            //get religions list
            var religions = from EnumReligion e in Enum.GetValues(typeof(EnumReligion))
                            select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.ReligionList = new SelectList(religions, "Id", "Name", person.PersonReligion);

            //get occupations list
            var occupations = from EnumOccupation e in Enum.GetValues(typeof(EnumOccupation))
                              select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.OccupationList = new SelectList(occupations, "Id", "Name", person.PersonOccupation);

            //get hobbys list
            var hobbys = from EnumHobby e in Enum.GetValues(typeof(EnumHobby))
                         select new { ID = e, Name = CommonHelper.GetStringValue(e) };

            viewModel.HobbyList = new SelectList(hobbys, "Id", "Name", person.PersonHobby);
            return(viewModel);
        }
        public ActionResult Edit(MCustomer customer, FormCollection formCollection, string customerId)
        {
            _mCustomerRepository.DbContext.BeginTransaction();
            RefAddress address = new RefAddress();
            RefPerson  person  = new RefPerson();

            {
                customer = _mCustomerRepository.Get(customerId);
                //customer.CustomerFaceTreatment = formCollection["CustomerFaceTreatment"];
                //customer.CustomerAllergy = formCollection["CustomerAllergy"];
                //customer.CustomerSkinProblem = formCollection["CustomerSkinProblem"];
                //customer.CustomerPlanTreatment = formCollection["CustomerPlanTreatment"];
                //customer.CustomerPhoneJakarta = formCollection["CustomerPhoneJakarta"];
                //customer.CustomerLetter = formCollection["CustomerLetter"];
                customer.ModifiedDate = DateTime.Now;
                customer.ModifiedBy   = User.Identity.Name;
                customer.DataStatus   = EnumDataStatus.Updated.ToString();

                address = customer.AddressId;
                TransferFormValuesTo(address, formCollection);
                //address.AddressLine1 = formCollection["AddressLine1"];
                //address.AddressLine2 = formCollection["AddressLine2"];
                //address.AddressRt = formCollection["AddressRt"];
                //address.AddressRw = formCollection["AddressRw"];
                //address.AddressCity = formCollection["AddressCity"];
                //address.AddressPostCode = formCollection["AddressPostCode"];
                //address.AddressPhone = formCollection["AddressPhone"];
                //address.AddressFax = formCollection["AddressFax"];
                //address.AddressEmail = formCollection["AddressEmail"];
                address.ModifiedDate = DateTime.Now;
                address.ModifiedBy   = User.Identity.Name;
                address.DataStatus   = EnumDataStatus.Updated.ToString();

                person = customer.PersonId;
                TransferFormValuesTo(person, formCollection);
                //person.PersonFirstName = formCollection["PersonFirstName"];
                //person.PersonAnotherName = formCollection["PersonAnotherName"];
                //person.PersonPob = formCollection["PersonPob"];
                //if (!string.IsNullOrEmpty(formCollection["PersonDob"]))
                //    person.PersonDob = Convert.ToDateTime(formCollection["PersonDob"]);
                //else
                //    person.PersonDob = null;
                //person.PersonMobile = formCollection["PersonMobile"];
                //person.PersonOccupation = formCollection["PersonJob"];
                //person.PersonOfficceName = formCollection["PersonOfficceName"];
                //person.PersonOfficceAddress = formCollection["PersonOfficceAddress"];
                //person.PersonOfficceCity = formCollection["PersonOfficceCity"];
                //person.PersonOfficcePostCode = formCollection["PersonOfficcePostCode"];
                //person.PersonOfficcePhone = formCollection["PersonOfficcePhone"];
                //person.PersonOfficceFax = formCollection["PersonOfficceFax"];
                //person.PersonReligion = formCollection["PersonReligion"];
                //person.PersonLastEdu = formCollection["PersonLastEdu"];
                //person.PersonMarriedStatus = formCollection["PersonMarriedStatus"];
                //person.PersonHobby = formCollection["PersonHobby"];
                person.ModifiedDate = DateTime.Now;
                person.ModifiedBy   = User.Identity.Name;
                person.DataStatus   = EnumDataStatus.Updated.ToString();

                _mCustomerRepository.Update(customer);
            }

            try
            {
                _mCustomerRepository.DbContext.CommitChanges();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success;
            }
            catch (Exception e)
            {
                _mCustomerRepository.DbContext.RollbackTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()]    = EnumSaveState.Failed;
                TempData[EnumCommonViewData.ErrorMessage.ToString()] = e.GetBaseException().Message;

                //throw e.GetBaseException();

                var result = new
                {
                    Success = false,
                    Message = e.Message
                };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            var resultx = new
            {
                Success = true,
                Message = @" <div class='ui-state-highlight ui-corner-all' style='padding: 5pt; margin-bottom: 5pt;'>
                            <p>
                                <span class='ui-icon ui-icon-info' style='float: left; margin-right: 0.3em;'></span>
                                Data berhasil disimpan.</p>
                        </div>"
            };

            return(Json(resultx, JsonRequestBehavior.AllowGet));
            //}

            //return View("Status");
        }
        public ActionResult Registration(MCustomer customer, FormCollection formCollection)
        {
            _mCustomerRepository.DbContext.BeginTransaction();
            RefAddress address = new RefAddress();
            RefPerson  person  = new RefPerson();

            TransferFormValuesTo(address, formCollection);
            address.SetAssignedIdTo(Guid.NewGuid().ToString());
            address.CreatedDate = DateTime.Now;
            address.CreatedBy   = User.Identity.Name;
            address.DataStatus  = EnumDataStatus.New.ToString();
            _refAddressRepository.Save(address);

            TransferFormValuesTo(person, formCollection);
            person.SetAssignedIdTo(Guid.NewGuid().ToString());
            person.CreatedDate = DateTime.Now;
            person.CreatedBy   = User.Identity.Name;
            person.DataStatus  = EnumDataStatus.New.ToString();
            _refPersonRepository.Save(person);

            //MCustomer customer = new MCustomer();
            //TransferFormValuesTo(customer, cust);
            if (customer == null)
            {
                customer = new MCustomer();
            }
            customer.SetAssignedIdTo(formCollection["Id"]);
            customer.CreatedDate = DateTime.Now;
            customer.CreatedBy   = User.Identity.Name;
            customer.DataStatus  = EnumDataStatus.New.ToString();

            customer.AddressId = address;
            customer.PersonId  = person;

            _mCustomerRepository.Save(customer);

            try
            {
                _mCustomerRepository.DbContext.CommitChanges();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success;
            }
            catch (Exception e)
            {
                _mCustomerRepository.DbContext.RollbackTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()]    = EnumSaveState.Failed;
                TempData[EnumCommonViewData.ErrorMessage.ToString()] = e.Message;

                //throw e.GetBaseException();
                var result = new
                {
                    Success = false,
                    Message = e.Message
                };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            var resultx = new
            {
                Success = true,
                Message = //Helper.ViewHelper.RenderPartialToString("~/Views/Shared/Status.ascx", "", null, this.ControllerContext.RequestContext)
                          @" <div class='ui-state-highlight ui-corner-all' style='padding: 5pt; margin-bottom: 5pt;'>
                            <p>
                                <span class='ui-icon ui-icon-info' style='float: left; margin-right: 0.3em;'></span>
                                Data berhasil disimpan.</p>
                        </div>"
            };

            return(Json(resultx, JsonRequestBehavior.AllowGet));
            //return View("Status");
        }