예제 #1
0
        public async Task Establish(ContractInputModel model)
        {
            if (model == null)
            {
                throw new ValidationBusinessException(ValidationMessage.InputInvalid);
            }

            if (model.FromId == Guid.Empty || model.ToId == Guid.Empty)
            {
                throw new ValidationBusinessException(ValidationMessage.IdInvalid);
            }

            if (model.FromId == model.ToId)
            {
                throw new ValidationBusinessException(ValidationMessage.ContractInvalid);
            }

            var exists = _repo.QueryMatchContract(model.FromId, model.ToId).Any(x => !x.Finished);

            if (exists)
            {
                throw new ValidationBusinessException(ValidationMessage.ContractExists);
            }

            var contract = new Contract()
            {
                FromId = model.FromId, ToId = model.ToId
            };

            await _repo.Add(contract);

            await _uow.Commit();
        }
예제 #2
0
        public IActionResult Post([FromBody] dynamic contract)
        {
            try
            {
                var _contract = new Contract()
                {
                    Name       = contract.Name,
                    StartDate  = contract.startDate,
                    EndDate    = contract.endDate,
                    Amount     = contract.amount,
                    EmployeeId = contract.employeeId
                };

                if (_contract == null)
                {
                    throw new ArgumentNullException(nameof(_contract));
                }
                if (_employeeRepository.GetSingle(_contract.EmployeeId) == null)
                {
                    throw new ArgumentNullException($"Department you want to delete has employees assigned.");
                }

                _contractRepository.Add(_contract);
                _contractRepository.Commit();

                return(Created($"/api/contract/", _contract));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> Create(DraftContract contract)
        {
            if (ModelState.IsValid == false)
            {
                return(View(contract));
            }
            var toSave = new Core.Domain.Model.Contract()
            {
                Currency = contract.Currency.Value,
                Name     = contract.Name,
                Note     = contract.Note,
                Type     = contract.Type.Value
            };

            var saved = contractRepository.Add(toSave);
            await contractRepository.Save();

            draftRepository.Add(new ContractDraft()
            {
                ContractId = saved.Id, Step = 1
            });
            await draftRepository.Save();

            return(RedirectToAction("Step", new { contractId = saved.Id }));
        }
예제 #4
0
        public async Task <Query.Contract> Handle(AddContractCommand request, CancellationToken cancellationToken)
        {
            var contractDomain = new Contract(request.Name);

            contractDomain.Validate();

            #region Persistence

            var contract = contractDomain.ToModel <Command.Contract>(_Mapper);

            await _ContractRepository.Add(contract);

            await _UnitOfWork.Commit();

            #endregion

            #region Bus

            var publishMessage = new Message();
            publishMessage.MessageType = "AddContract";
            var response = contractDomain.ToQueryModel <Query.Contract>(_Mapper);
            publishMessage.SetData(response);

            await _Bus.SendMessage(publishMessage);

            #endregion

            return(response);
        }
예제 #5
0
        public void CreateContract(ContractViewModel model)
        {
            Contract newContract = _mapper.Map <Contract>(model);

            _contractRepository.Add(newContract);
            _contractRepository.Save();
        }
 public void Add(Contract contract)
 {
     if (null == contract)
     {
         return;
     }
     contractRepository.Add(contract);
 }
예제 #7
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateContract request, CancellationToken cancellationToken)
        {
            var contract = new Contract(request.TemplateId, request.CustomerId, request.TenementId, request.StartDate, request.EndDate);

            _contractRepository.Add(contract);
            await _contractRepository.UnitOfWork.SaveChangesAsync(cancellationToken);

            return(CreatedAtAction(nameof(GetAsync), new { id = contract.Id }, new { ContractId = contract.Id }));
        }
        public IActionResult Create(int id, string naam)
        {
            string                 gebruikersnaam = User.Identity.Name;
            Gebruiker              gebruiker      = _gebruikerRepository.GetByGebruikersnaamKlant(gebruikersnaam);
            ContractType           ct             = _contractTypeRepository.GetById(id);
            IEnumerable <Contract> contracten     = _contractRepository.GetByGebruiker(gebruiker);
            Contract               contract       = new Contract(ct, DateTime.Now, gebruiker);

            _contractRepository.Add(contract);
            _contractRepository.SaveChanges();
            TempData["message"] = $"{contract.ContractTypeNaam} contract succesvol aangemaakt!";
            return(RedirectToAction(nameof(Index)));
        }
예제 #9
0
 public bool AddContract(ContractsDTO contract)
 {
     try
     {
         Contract contractModel = modalFactory.Create(contract);
         _IContractRepository.Add(contractModel);
         _IContractRepository.SaveChages();
         return(true);
     } catch (Exception ex)
     {
         return(false);
     }
 }
        public void DeploySols()
        {
            var dict = GetByteCodeStringForSols();

            foreach (var key in dict.Keys)
            {
                var entity = new Contract()
                {
                    Name    = key,
                    Address = dict[key]
                };
                _contractRepository.Add(entity);
            }
            _dbContext.SaveChanges();
        }
예제 #11
0
 public bool AddContract(ContractsDTO contract)
 {
     try
     {
         var pipeline     = IpipelineRepository.GetById(contract.PipelineID);
         var pipelineDuns = pipeline.DUNSNo;
         contract.PipeDuns = pipelineDuns;
         Contract contractModel = modalFactory.Create(contract);
         _IContractRepository.Add(contractModel);
         _IContractRepository.SaveChages();
         return(true);
     } catch (Exception ex)
     {
         return(false);
     }
 }
 private bool AddContract(List <Contract> existingContracts, string contractNumber)
 {
     if (string.IsNullOrWhiteSpace(contractNumber))
     {
         return(false);
     }
     if (!existingContracts.Any(item => item.Number.Equals(contractNumber, StringComparison.OrdinalIgnoreCase)))
     {
         Contract temp = new Contract(0)
         {
             Number = contractNumber
         };
         contractRepository.Add(temp);
         existingContracts.Add(temp);
         return(true);
     }
     return(false);
 }
예제 #13
0
        public MainViewModel(IClientRepository clientsRepo, IBuildingRepository buildingRepo, IContractRepository contractRepo)
        {
            // передача значений полю от переданного объекта клиенты
            this.clientsRepo  = clientsRepo;
            this.buildingRepo = buildingRepo;
            this.contractRepo = contractRepo;
            // заполенение свойства элементами дерева из БД
            ListClient   = new ObservableCollection <Client>(this.clientsRepo.GetAll());
            DayOfTheWeek = DateTime.Now.DayOfWeek.ToString();
            DispatcherTimer t = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 50), DispatcherPriority.Background, t_Tick, Dispatcher.CurrentDispatcher); t.IsEnabled = true;

            //установка выбранного объекта дерева в свойство
            SetSelectedItemCommand = new RelayCommand <object>(item =>
            {
                if (item is Client)
                {
                    SelectedClient     = item as Client;
                    SelectedBuilding   = null;
                    SelectedContract   = null;
                    SelectedName       = SelectedClient.Organization;
                    DynamicUserControl = new UserControlClients(SelectedClient);
                    ChartsUserControl  = new UserControlDiagram();
                    SelectedObject     = 1;
                    ParentClient       = null;
                    ParentContract     = null;
                }
                else if (item is Contract)
                {
                    SelectedContract   = item as Contract;
                    SelectedClient     = null;
                    SelectedBuilding   = null;
                    SelectedName       = SelectedContract.ContractNumber;
                    DynamicUserControl = new UserControlContracts(SelectedContract);
                    ChartsUserControl  = new UserControlDiagram(SelectedContract);
                    SelectedObject     = 2;
                    ParentClient       = ListClient.First(clnt => clnt.ClientID == SelectedContract.ClientID);
                    ParentContract     = null;
                }
                else if (item is Building)
                {
                    SelectedBuilding   = item as Building;
                    SelectedContract   = null;
                    SelectedClient     = null;
                    SelectedName       = SelectedBuilding.NameOfTheObject;
                    DynamicUserControl = new UserControlBuildings(SelectedBuilding);
                    ChartsUserControl  = new UserControlDiagram();
                    SelectedObject     = 3;
                    ParentContract     = contractRepo.GetContractById(SelectedBuilding);                                          //получили родительский контракт из БД
                    ParentClient       = ListClient.First(client => client.ClientID == ParentContract.ClientID);                  //получили родительского клиента из ListClient
                    ParentContract     = ParentClient.Contract.First(ctr => ctr.ContractNumber == ParentContract.ContractNumber); //переписали контракт на контракт из ListClient
                }
            });

            #region commands
            // удалить объект
            Action DeleteBuildingAction = () =>
            {
                Building bld = SelectedBuilding;
                buildingRepo.Delete(bld);

                ParentContract.Building.Remove(bld);
            };
            actions.Add(DeleteBuildingAction);

            DeleteBuildingCmd = new RelayCommand(DeleteBuildingAction, () => SelectedObject == 3);
            // редактировать объект
            UpdateBuildingCmd = new RelayCommand(() =>
            {
                if (SelectedBuilding != null)
                {
                    BuildingDialog buildDlg = new BuildingDialog(SelectedBuilding);
                    if (buildDlg.ShowDialog() == true)
                    {
                        buildingRepo.Update(buildDlg.NewBuilding);
                        SelectedBuilding = buildDlg.NewBuilding;
                    }
                }
            }, () => SelectedObject == 3);
            // добавить объект
            AddBuildingCmd = new RelayCommand(() =>
            {
                Building bld;
                BuildingDialog buildDlg = new BuildingDialog(SelectedContract);
                if (buildDlg.ShowDialog() == true)
                {
                    bld = buildDlg.NewBuilding;
                    buildingRepo.Add(ref bld);
                    if (SelectedContract.Building == null)
                    {
                        SelectedContract.Building = new ObservableCollection <Building>();
                    }
                    SelectedContract.Building.Add(bld);
                }
            }, () => SelectedObject == 2);
            // редактировать клиента
            UpdateClientCmd = new RelayCommand(() =>
            {
                Client clt;
                ClientDialog clntDlg = new ClientDialog(SelectedClient);
                if (clntDlg.ShowDialog() == true)
                {
                    clt = clntDlg.NewClient;
                    clientsRepo.Update(clntDlg.NewClient);
                }
            }, () => SelectedObject == 1);
            // добавить клиента
            AddClientCmd = new RelayCommand(() =>
            {
                Client clt;
                ClientDialog clntDlg = new ClientDialog();
                if (clntDlg.ShowDialog() == true)
                {
                    clt = clntDlg.NewClient;
                    clientsRepo.Add(ref clt);
                    ListClient.Add(clt);
                }
            }, () => SelectedObject == 1);
            // добавить контракт
            AddContractCmd = new RelayCommand(() =>
            {
                Contract contract;
                ContractDialog contractDialog = new ContractDialog(SelectedClient);
                if (contractDialog.ShowDialog() == true)
                {
                    contract          = contractDialog.NewContract;
                    contract.ClientID = SelectedClient.ClientID;
                    contractRepo.Add(ref contract);
                    if (SelectedClient.Contract == null)
                    {
                        SelectedClient.Contract = new ObservableCollection <Contract>();
                    }
                    SelectedClient.Contract.Add(contract);
                }
            }, () => SelectedObject == 1);
            // редактировать контракт
            UpdateContractCmd = new RelayCommand(() =>
            {
                Contract contract;
                ContractDialog contractDialog = new ContractDialog(SelectedContract);
                if (contractDialog.ShowDialog() == true)
                {
                    contract = contractDialog.NewContract;
                    contractRepo.Update(contractDialog.NewContract);
                }
            }, () => SelectedObject == 2);
            // удалить контракт
            DeleteContractCmd = new RelayCommand(() =>
            {
                Contract contract = SelectedContract;
                contractRepo.Delete(SelectedContract);
                if (SelectedContract.Building != null)
                {
                    SelectedContract.Building.Clear();
                }
                ParentClient.Contract.Remove(SelectedContract);
            }, () => SelectedObject == 2);
            // удалить клиента
            DeleteClientCmd = new RelayCommand(() =>
            {
                Client contract = SelectedClient;
                clientsRepo.Delete(SelectedClient);
                if (SelectedClient.Contract != null)
                {
                    SelectedClient.Contract.Clear();
                }
                ListClient.Remove(SelectedClient);
            }, () => SelectedObject == 1);
            // вывести сметы в XML
            BuildingToXmlCmd = new RelayCommand(() =>
            {
                XDocument BuildingsXML = new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    new XComment("Lizzard #smiles #loveMVVM #IAmGoodStudent"),
                    new XElement("Buildings",
                                 buildingRepo.GetAll().Select(bld =>
                                                              new XElement("Building",
                                                                           new XAttribute("ID", bld.ObjectID),
                                                                           new XElement("Name", bld.NameOfTheObject),
                                                                           new XElement("Contract_Number", bld.ContractNumber),
                                                                           new XElement("Issue_Date", bld.IssueDate.ToLongDateString()),
                                                                           new XElement("Cost", bld.CostOfTheObject)
                                                                           )
                                                              )
                                 ));
                BuildingsXML.Save(@"Buildings.xml");
            });
            #endregion
        }
예제 #14
0
        public void Insert(ContractViewModel model)
        {
            var contractType = AutoMapper.Mapper.Map <ContractViewModel, Contract>(model);

            _repository.Add(contractType);
        }
예제 #15
0
 public int Add(Contract contractModel)
 {
     return(_iContractRepository.Add(contractModel));
 }