예제 #1
0
        public ActionResult Insert(TUnit viewModel, FormCollection formCollection)
        {
            UpdateNumericData(viewModel, formCollection);

            TUnit unitToInsert = new TUnit();

            TransferFormValuesTo(unitToInsert, viewModel);
            unitToInsert.UnitTypeId = _mUnitTypeRepository.Get(formCollection["UnitTypeId"]);
            unitToInsert.UnitStatus = EnumUnitStatus.New.ToString();

            unitToInsert.SetAssignedIdTo(viewModel.Id);
            unitToInsert.CreatedDate = DateTime.Now;
            unitToInsert.CreatedBy   = User.Identity.Name;
            unitToInsert.DataStatus  = EnumDataStatus.New.ToString();
            _tUnitRepository.Save(unitToInsert);

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

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

            return(Content("success"));
        }
예제 #2
0
        private void GenerateEachUnit(MUnitType unitType)
        {
            if (unitType.UnitTypeTotal.HasValue)
            {
                TUnit unit;
                for (int i = 0; i < unitType.UnitTypeTotal.Value; i++)
                {
                    unit = new TUnit();
                    unit.CostCenterId = unitType.CostCenterId;
                    unit.UnitTypeId   = unitType;
                    unit.UnitStatus   = EnumUnitStatus.New.ToString();
                    unit.UnitNo       = (i + 1).ToString();

                    unit.SetAssignedIdTo(Guid.NewGuid().ToString());
                    unit.CreatedDate = DateTime.Now;
                    unit.CreatedBy   = User.Identity.Name;
                    unit.DataStatus  = EnumDataStatus.New.ToString();
                    _tUnitRepository.Save(unit);
                }
            }
        }