コード例 #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
        public ActionResult Update(MUnitType viewModel, FormCollection formCollection)
        {
            MUnitType mUnitTypeToUpdate = _mUnitTypeRepository.Get(viewModel.Id);

            TransferFormValuesTo(mUnitTypeToUpdate, viewModel);
            mUnitTypeToUpdate.CostCenterId = _mCostCenterRepository.Get(formCollection["CostCenterId"]);
            mUnitTypeToUpdate.ModifiedDate = DateTime.Now;
            mUnitTypeToUpdate.ModifiedBy   = User.Identity.Name;
            mUnitTypeToUpdate.DataStatus   = EnumDataStatus.Updated.ToString();
            _mUnitTypeRepository.Update(mUnitTypeToUpdate);

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

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

            return(Content("success"));
        }