Esempio n. 1
0
        public NewlyCreatedObjectId Create(CreateNRelationTypeIncomeModel model, Guid?companyId, Guid userId)
        {
            var companiesId = _companyRepository.GetAll().Where(c => c.CreatedByCompanyId == companyId).Select(cc => cc.Id).ToList();

            if (_nRelationTypeRepository.Any(nr => nr.Name == model.Name && (nr.CreatedByCompanyId == companyId ||
                                                                             companiesId.Contains(nr.CreatedByCompanyId)))
                )
            {
                throw new AlreadyExistException();
            }

            var dbNRelationType = new RelationType
            {
                CreatedById        = userId,
                CreatedByCompanyId = companyId.GetValueOrDefault(Guid.Empty),
                CreatedDate        = DateTime.Now,
                Name         = model.Name,
                ModifiedDate = DateTime.Now,
            };

            _nRelationTypeRepository.Add(dbNRelationType);

            return(new NewlyCreatedObjectId(dbNRelationType.Id));
        }
Esempio n. 2
0
 public IActionResult Create([FromBody] CreateNRelationTypeIncomeModel model)
 {
     return(OkResult(_nRelationTypeService.Create(model, CurrentUser.CompanyId, CurrentUser.Id)));
 }