コード例 #1
0
 public MCustomer Insert(Domain.MCustomer cust)
 {
     _customerRepository.DbContext.BeginTransaction();
     _customerRepository.Save(cust);
     _customerRepository.DbContext.CommitTransaction();
     return(cust);
 }
コード例 #2
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);

            MCustomer customer = new MCustomer();

            TransferFormValuesTo(customer, viewModel);
            customer.SetAssignedIdTo(viewModel.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();
            }
            catch (Exception e)
            {
                _mCustomerRepository.DbContext.RollbackTransaction();

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

            return(Content("success"));
        }