예제 #1
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"));
        }
예제 #2
0
        public ActionResult Customers_Create([DataSourceRequest] DataSourceRequest request, CustomerViewModel custVM)
        {
            if (custVM != null && ModelState.IsValid)
            {
                MCustomer cust = new MCustomer();
                cust.SetAssignedIdTo(Guid.NewGuid().ToString());

                ConvertToCustomer(custVM, cust);

                cust.CreatedDate = DateTime.Now;
                cust.CreatedBy   = User.Identity.Name;
                cust.DataStatus  = "New";

                _customerTasks.Insert(cust);
            }

            return(Json(new[] { custVM }.ToDataSourceResult(request, ModelState)));
        }