예제 #1
0
        public CompanyDTO SaveCompany(CompanyDTO company)
        {
            if (company == null)
            {
                return(null);
            }
            if (string.IsNullOrWhiteSpace(company.FullName))
            {
                throw new ArgumentException("Full name is missing.");
            }
            if (string.IsNullOrWhiteSpace(company.ShortName))
            {
                throw new ArgumentException("Short name is missing");
            }
            Company savedCompany = null;

            if (company.Id.HasValue)
            {
                savedCompany = companiesRepository.Update(Company.Hydrate(company));
            }
            else
            {
                savedCompany = companiesRepository.Insert(Company.Hydrate(company));
            }
            if (savedCompany != null)
            {
                return(savedCompany.getDTO());
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        public async Task <JsonResult> SyncCompanies()
        {
            var knownCompanies = await _companiesRepository.GetAllCompanies();

            var radarioCompanies = mf.CompanyManager.GetAllCompanies();
            var updateCount      = 0;
            var insertCount      = 0;

            foreach (var radarioCompany in radarioCompanies)
            {
                var entity = knownCompanies.SingleOrDefault(x => x.CompanyId == radarioCompany.Id);
                if (entity == null)
                {
                    entity = new Company()
                    {
                        CompanyId      = radarioCompany.Id,
                        CompanyTitle   = radarioCompany.Title,
                        PublicGuid     = Guid.NewGuid(),
                        FullAccessGuid = Guid.NewGuid()
                    };
                    await _companiesRepository.Insert(entity);

                    insertCount++;
                }
                else
                {
                    if (!radarioCompany.Title.Equals(entity.CompanyTitle,
                                                     StringComparison.InvariantCultureIgnoreCase))
                    {
                        entity.CompanyTitle = radarioCompany.Title;
                        await _companiesRepository.Update(entity);

                        updateCount++;
                    }
                }
            }
            return(Json(new {
                Updated = updateCount,
                CreatedNew = insertCount
            }, JsonSerializerSettings));
        }
예제 #3
0
 public void Add(Company company)
 {
     _repository.Insert(company);
     _unitOfWork.Commit();
 }
 public IHttpActionResult Post(Company comp)
 {
     _repository.Insert(comp);
     _repository.Save();
     return(Ok(comp));
 }