예제 #1
0
        //public ViewResult Create()
        //{
        //    var model = new TaxIncomePersonDetailViewModel();

        //    return View(model);
        //}


        public ActionResult Create(int?staffId, int?taxPersonId)
        {
            bool anyStaff  = staffsRepository.GetAllStaffs().Any(n => n.Id == staffId);
            bool anyPerson = staffsRepository.GetAllStaffs().Any(n => n.Id == taxPersonId);

            if (!anyStaff || !anyPerson)
            {
                return(Content("error"));
            }

            var TaxIncomePersonDetail = new TaxIncomePersonDetail();

            TaxIncomePersonDetail.IsDeleted         = false;
            TaxIncomePersonDetail.CreatedUserId     = WebSecurity.CurrentUserId;
            TaxIncomePersonDetail.ModifiedUserId    = WebSecurity.CurrentUserId;
            TaxIncomePersonDetail.AssignedUserId    = WebSecurity.CurrentUserId;
            TaxIncomePersonDetail.CreatedDate       = DateTime.Now;
            TaxIncomePersonDetail.ModifiedDate      = DateTime.Now;
            TaxIncomePersonDetail.StaffId           = staffId;
            TaxIncomePersonDetail.TaxIncomePersonId = taxPersonId;
            TaxIncomePersonDetailRepository.InsertTaxIncomePersonDetail(TaxIncomePersonDetail);

            return(Content("ok"));
        }
예제 #2
0
        public ActionResult Create(TaxIncomePersonViewModel model)
        {
            var _model = TaxIncomePersonRepository.GetAllTaxIncomePerson().Where(n => n.Code == model.Code);

            if (_model != null && _model.Count() > 0)
            {
                //StaffsTaxModel
                string staffids = Request["StaffIds"];
                if (!string.IsNullOrEmpty(staffids))
                {
                    List <string>         arrStaffIds = staffids.Split(',').ToList();
                    List <StaffsTaxModel> modelStaff  = staffsRepository.GetvwAllStaffs()
                                                        .Select(item => new StaffsTaxModel
                    {
                        Id           = item.Id,
                        Name         = item.Name,
                        Code         = item.Code,
                        DistrictName = item.DistrictName,
                        BranchId     = item.Sale_BranchId,
                        Email        = item.Email,
                        EndDate      = item.EndDate,
                        StartDate    = item.StartDate,
                        Gender       = item.Gender,
                        IdCardNumber = item.IdCardNumber,
                        BranchName   = item.BranchName,
                        ContryName   = item.CountryId,
                        ProvinceName = item.ProvinceName,
                        WardName     = item.WardName
                    }).OrderByDescending(m => m.Id).ToList();

                    model.ListStaffsTax   = modelStaff.Where(n => arrStaffIds.Contains(n.Id.ToString()));
                    ViewBag.FailedMessage = "Mã số thuế đã tồn tại";
                }

                return(View(model));
            }
            if (ModelState.IsValid)
            {
                //Add Taxperson
                var TaxIncomePerson = new TaxIncomePerson();
                AutoMapper.Mapper.Map(model, TaxIncomePerson);
                TaxIncomePerson.IsDeleted      = false;
                TaxIncomePerson.CreatedUserId  = WebSecurity.CurrentUserId;
                TaxIncomePerson.ModifiedUserId = WebSecurity.CurrentUserId;
                TaxIncomePerson.AssignedUserId = WebSecurity.CurrentUserId;
                TaxIncomePerson.CreatedDate    = DateTime.Now;
                TaxIncomePerson.ModifiedDate   = DateTime.Now;


                TaxIncomePersonRepository.InsertTaxIncomePerson(TaxIncomePerson);

                //Add Staffs to Detail
                string staffids = Request["StaffIds"];
                if (!string.IsNullOrEmpty(staffids))
                {
                    string[] arrStaffIds = staffids.Split(',');
                    for (int i = 0; i < arrStaffIds.Count(); i++)
                    {
                        var TaxIncomePersonDetail = new TaxIncomePersonDetail();
                        TaxIncomePersonDetail.IsDeleted         = false;
                        TaxIncomePersonDetail.CreatedUserId     = WebSecurity.CurrentUserId;
                        TaxIncomePersonDetail.ModifiedUserId    = WebSecurity.CurrentUserId;
                        TaxIncomePersonDetail.AssignedUserId    = WebSecurity.CurrentUserId;
                        TaxIncomePersonDetail.CreatedDate       = DateTime.Now;
                        TaxIncomePersonDetail.ModifiedDate      = DateTime.Now;
                        TaxIncomePersonDetail.StaffId           = int.Parse(arrStaffIds[i]);
                        TaxIncomePersonDetail.TaxIncomePersonId = TaxIncomePerson.Id;

                        taxIncomePersonDetailRepository.InsertTaxIncomePersonDetail(TaxIncomePersonDetail);
                    }
                }

                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }