Esempio n. 1
0
        private void UpdateCreditProcess(CreditProcess creditProcess, IEnumerable <ProcessFlowViewModel> creditProcessFlowsList)
        {
            _creditProcessesRepository.UpdateCreditProcess(creditProcess);

            foreach (var creditProcessFlow in creditProcessFlowsList)
            {
                var creditProcessFlowFormed = Map(creditProcessFlow);
                if (creditProcessFlow.IsNew)
                {
                    creditProcessFlowFormed.CreatedAt = DateTime.Now;
                    creditProcessFlowFormed.UpdatedAt = DateTime.Now;

                    var flowId           = _creditProcessesRepository.AddCreditProcessFlow(creditProcessFlowFormed);
                    var creditProcessLog = CreateNewCreditProcessLog(creditProcessFlowFormed);
                    creditProcessFlowFormed.CreditProcessXCompanyId = flowId;
                    _creditProcessesLogManagement.AddCreditProcessLog(creditProcessLog);
                }
                else
                {
                    creditProcessFlowFormed.UpdatedAt = creditProcessFlowFormed.UpdatedAt ?? DateTime.Now;
                    if (creditProcessFlow.IsDeleted)
                    {
                        _creditProcessesRepository.DeleteCreditProcessFlow(creditProcessFlowFormed);
                    }
                    else
                    {
                        var creditProcessLog = UpdateCreditProcessLog(creditProcessFlowFormed);
                        _creditProcessesLogManagement.AddCreditProcessLog(creditProcessLog);
                        _creditProcessesRepository.UpdateCreditProcessFlow(creditProcessFlowFormed);
                    }
                }
            }
        }
        public int AddCreditProcess(CreditProcess creditProcess)
        {
            _databaseModel.CreditProcesses.Add(creditProcess);
            _databaseModel.SaveChanges();

            return(creditProcess.CreditProcessId);
        }
Esempio n. 3
0
        private static CreditProcess Map(EditViewModel editViewModel)
        {
            var creditProcess = new CreditProcess
            {
                CreditProcessId = editViewModel.CreditProcessId,
                CustomerId      = editViewModel.Customer.CustomerId,
                UserId          = editViewModel.Salesman.UserId,
                CreditStatusId  = editViewModel.CreditStatus.CreditStatusId,
                Product         = editViewModel.Product,
                //TODO: missing list of current flows with the different companies
            };

            return(creditProcess);
        }
Esempio n. 4
0
        private void AddCreditProcess(CreditProcess creditProcess, List <ProcessFlowViewModel> creditProcessFlowsList)
        {
            var creditProcessId = _creditProcessesRepository.AddCreditProcess(creditProcess);

            foreach (var creditProcessFlow in creditProcessFlowsList)
            {
                creditProcessFlow.CreditProcessId = creditProcessId;
                var creditProcessFlowFormed = Map(creditProcessFlow);
                creditProcessFlowFormed.CreatedAt = DateTime.Now;
                creditProcessFlowFormed.UpdatedAt = DateTime.Now;

                var flowId = _creditProcessesRepository.AddCreditProcessFlow(creditProcessFlowFormed);
                creditProcessFlowFormed.CreditProcessXCompanyId = flowId;
                var creditProcessLog = CreateNewCreditProcessLog(creditProcessFlowFormed);
                _creditProcessesLogManagement.AddCreditProcessLog(creditProcessLog);
            }
        }
        public void UpdateCreditProcess(CreditProcess creditProcess)
        {
            var entry = _databaseModel.Entry(creditProcess);

            if (entry.State == EntityState.Detached)
            {
                var set            = _databaseModel.Set <CreditProcess>();
                var attachedEntity = set.Find(creditProcess.CreditProcessId);  // You need to have access to key

                if (attachedEntity != null)
                {
                    var attachedEntry = _databaseModel.Entry(attachedEntity);
                    attachedEntry.CurrentValues.SetValues(creditProcess);
                }
                else
                {
                    entry.State = EntityState.Modified; // This should attach entity
                }
            }

            _databaseModel.SaveChanges();
        }