Ejemplo n.º 1
0
        public async Task <ResponseObject <CompanyViewModel> > UpdateCompany(CompanyViewModel companyVm)
        {
            ResponseObject <CompanyViewModel> responseObject = new ViewModels.ResponseObject <CompanyViewModel>();

            Company company = _context.Company.Find(companyVm.Id);

            ////validating company
            var validation = CompanyValidation.ValidationForCompany(companyVm);

            if (!validation.Valid)
            {
                responseObject.Message = validation.Message;
                responseObject.Success = false;
                return(responseObject);
            }

            // checking for duplicate isins
            var checkIsin = await _context.Company.FirstOrDefaultAsync(x => x.ISIN.ToLower() == companyVm.ISIN.ToLower() && x.Id != companyVm.Id);

            if (checkIsin != null)
            {
                responseObject.Message = "ISIN already exists";
                responseObject.Success = false;
                return(responseObject);
            }

            if (company != null)
            {
                company.Name     = companyVm.Name;
                company.Ticker   = companyVm.Ticker;
                company.WebSite  = companyVm.WebSite;
                company.Exchange = companyVm.Exchange;
                company.ISIN     = companyVm.ISIN;


                _context.Update(company);

                await _context.SaveChangesAsync();
            }
            responseObject.Success = true;
            responseObject.Result  = MappingToViewModel(company);

            return(responseObject);
        }
Ejemplo n.º 2
0
        public async Task <ResponseObject <CompanyViewModel> > GetCompanyByIsin(string isin)
        {
            ResponseObject <CompanyViewModel> responseObject = new ViewModels.ResponseObject <CompanyViewModel>();

            Company company = await _context.Company.FirstOrDefaultAsync(x => x.ISIN.ToLower() == isin.ToLower());

            if (company != null)
            {
                responseObject.Result  = MappingToViewModel(company);
                responseObject.Success = true;
            }
            else
            {
                responseObject.Success = false;
                responseObject.Message = "Company not found";
            }

            return(responseObject);
        }
Ejemplo n.º 3
0
        public async Task <ResponseObject <CompanyViewModel> > CreateCompany(CompanyViewModel companyVm)
        {
            ResponseObject <CompanyViewModel> responseObject = new ViewModels.ResponseObject <CompanyViewModel>();


            ////validating company
            var validation = CompanyValidation.ValidationForCompany(companyVm);

            if (!validation.Valid)
            {
                responseObject.Message = validation.Message;
                responseObject.Success = false;

                return(responseObject);
            }

            // checking for duplicate isins
            var checkIsin = await _context.Company.FirstOrDefaultAsync(x => x.ISIN.ToLower() == companyVm.ISIN.ToLower());

            if (checkIsin != null)
            {
                responseObject.Message = "ISIN already exists";
                responseObject.Success = false;

                return(responseObject);
            }


            Company company = MappingToCompany(companyVm);

            _context.Company.Add(company);
            await _context.SaveChangesAsync();

            responseObject.Result  = MappingToViewModel(company);
            responseObject.Success = true;


            return(responseObject);
        }