public async Task <IHttpActionResult> PostCompany(CompanyBindingModel model)
        {
            var userId = this.User.Identity.GetUserId();

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }
            if (model == null)
            {
                return(this.BadRequest("Invalid input data"));
            }

            if (userId == null)
            {
                return(this.BadRequest("Invalid session token."));
            }

            var company = new Company()
            {
                Name      = model.Name,
                CreatedOn = DateTime.Now,
                Email     = model.Email,
                OwnerId   = userId
            };

            this.Data.Companies.Add(company);
            await this.Data.SaveChangesAsync();

            return(this.StatusCode(HttpStatusCode.Created));
        }
Example #2
0
        public async Task <IActionResult> Update([FromForm] CompanyBindingModel model)
        {
            var entity = await _repository.FindAsync(model.Id);

            if (entity == null)
            {
                return(BadRequest(new BadRequestResponseModel(ErrorTypes.BadRequest, ErrorMessages.ItemNotFound)));
            }

            entity.Name    = model.Name;
            entity.Address = model.Address;
            entity.Phone   = model.Phone;
            entity.Website = model.Website;

            if (model.Logo != null && model.Logo.Length > 0)
            {
                var fileName = model.Logo.FileName.ToUniqueFileName();
                var savePath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.COMPANIES, fileName);
                await model.Logo.CopyToAsync(new FileStream(savePath, FileMode.Create));

                entity.LogoUrl = (new string[] { UploadFolders.UPLOAD_PATH, UploadFolders.COMPANIES, fileName }).ToWebFilePath();
            }

            entity.UpdatedAt = DateTime.Now;
            entity.UpdatedBy = UserId;

            await _repository.UpdateAsync(entity);

            return(Ok());
        }
Example #3
0
        public ActionResult _Index(int?id)
        {
            checkVatPortTypeClient client = new checkVatPortTypeClient();
            Vat vat;
            CompanyBindingModel companyDetails = new CompanyBindingModel();

            using (InnovasysVatContext context = new InnovasysVatContext())
            {
                vat = context.Vats.FirstOrDefault(v => v.Id == id);
            }

            if (vat != null)
            {
                string countryCode = vat.VatNumber.Substring(0, 2);
                string vatNumber   = vat.VatNumber.Substring(2, vat.VatNumber.Length - 2).TrimEnd();
                client.checkVat(ref countryCode, ref vatNumber, out var isValid, out var name, out var address);
                companyDetails.VatNumber   = vatNumber;
                companyDetails.CountryCode = countryCode;
                companyDetails.Address     = address;
                companyDetails.Name        = name;
                companyDetails.IsValid     = isValid;
            }

            client.Close();

            return(PartialView(companyDetails));
        }
        public async Task <IActionResult> Edit([FromBody] CompanyBindingModel company)
        {
            await companyService.UpdateAsync(new Core.Models.Company
            {
                Name     = company.Name,
                Exchange = company.Exchange,
                Ticker   = company.Ticker,
                ISIN     = company.ISIN,
                Website  = company?.Website
            });

            return(Ok());
        }
        public async Task <IActionResult> Create([FromBody] CompanyBindingModel company)
        {
            await companyService.AddAsync(new Core.Models.Company
            {
                Name     = company.Name,
                Exchange = company.Exchange,
                Ticker   = company.Ticker,
                ISIN     = company.ISIN,
                Website  = company?.Website
            });

            // TODO: Return id ??
            return(Ok());
        }
Example #6
0
        public async Task <IActionResult> Create([FromForm] CompanyBindingModel model)
        {
            var entity = _mapper.Map <Company>(model);

            entity.CreatedBy = UserId;

            if (model.Logo != null && model.Logo.Length > 0)
            {
                var fileName = model.Logo.FileName.ToUniqueFileName();
                var savePath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.COMPANIES, fileName);
                await model.Logo.CopyToAsync(new FileStream(savePath, FileMode.Create));

                entity.LogoUrl = (new string[] { UploadFolders.UPLOAD_PATH, UploadFolders.COMPANIES, fileName }).ToWebFilePath();
            }

            await _repository.AddAsync(entity);

            return(Ok());
        }
        public async Task <IHttpActionResult> PostCompany(CompanyBindingModel model)
        {
            // Get the current User
            var user = db.Users.Find(User.Identity.GetUserId());

            // Get the users owner profile
            var owner      = user.Profiles.OfType <Owner>().FirstOrDefault();
            var driver     = user.Profiles.OfType <Driver>().FirstOrDefault();
            var manager    = user.Profiles.OfType <Manager>().FirstOrDefault();
            var accountant = user.Profiles.OfType <Accountant>().FirstOrDefault();

            // Get existing addresses with the same PlaceId
            var existingAddress = db.Addresses.FirstOrDefault(a => a.PlaceId == model.PlaceId);

            Address address;

            // Is there any addresses?
            if (existingAddress == null)
            {
                // No so we need to check with Google and get the details
                var addressResult = await GeocodingService.GetAddress(model.PlaceId);

                // Create the new Address in database
                address = new Address
                {
                    Id          = Guid.NewGuid(),
                    PlaceId     = addressResult.PlaceId,
                    Coordinates = new Coordinates
                    {
                        Id        = Guid.NewGuid(),
                        Latitude  = addressResult.Latitude,
                        Longitude = addressResult.Longitude
                    }
                };
            }
            else
            {
                // Theres an existing adress stored so use that one
                address = existingAddress;
            }

            // Setup the new company
            var newCompany = new Company
            {
                Id                 = Guid.NewGuid(),
                Name               = model.Name,
                AutoAccept         = model.AutoAccept,
                HighRate           = model.HighRate,
                LowRate            = model.LowRate,
                Vat                = model.Vat,
                VatNumber          = model.VatNumber,
                Address            = address,
                AutoAcceptDistance = model.AutoAcceptDistance,
                Owner              = owner,
                Personal           = false
            };

            // Add the owners profiles to the company
            newCompany.Profiles.Add(driver);
            newCompany.Profiles.Add(manager);
            newCompany.Profiles.Add(accountant);

            // Save the changes
            await db.SaveChangesAsync();

            // Return the new company's details
            return(Ok(new CompanyViewModel
            {
                Id = newCompany.Id.ToString(),
                Name = model.Name,
                HighRate = model.HighRate,
                LowRate = model.LowRate,
                Personal = false
            }));
        }