Beispiel #1
0
        public async Task <IActionResult> Edit(int?id, CompanyTaxiViewModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var companyTaxi = await _context.CompanyTaxis.SingleOrDefaultAsync(m => m.Id == id);

            if (companyTaxi == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                companyTaxi.Name          = model.Name;
                companyTaxi.PhoneCompany  = model.PhoneCompany;
                companyTaxi.AddressOffice = model.AddressOffice;
                if (model.Logo != null)
                {
                    var filename = Path.GetFileName(ContentDispositionHeaderValue
                                                    .Parse(model.Logo.ContentDisposition)
                                                    .FileName.Trim('"'));
                    var extension = Path.GetExtension(filename);

                    if (extension != ".jpg" && extension != ".png")
                    {
                        throw new ArgumentException();
                    }

                    var serverPath = Path.Combine(_env.WebRootPath, "images");
                    serverPath = Path.Combine(serverPath, filename);

                    using (FileStream SourceStream = System.IO.File.Open(serverPath, FileMode.OpenOrCreate))
                    {
                        await model.Logo.CopyToAsync(SourceStream);
                    }

                    companyTaxi.LogoUrl = "/images/" + filename;
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            model.Item = companyTaxi;
            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(CompanyTaxiViewModel model)
        {
            if (ModelState.IsValid)
            {
                var taxicompany = new CompanyTaxi
                {
                    AddressOffice = model.AddressOffice,
                    PhoneCompany  = model.PhoneCompany,
                    Name          = model.Name
                };
                if (model.Logo != null)
                {
                    var filename = Path.GetFileName(ContentDispositionHeaderValue
                                                    .Parse(model.Logo.ContentDisposition)
                                                    .FileName.Trim('"'));
                    var extension = Path.GetExtension(filename);

                    if (extension != ".jpg" && extension != ".png")
                    {
                        throw new ArgumentException();
                    }

                    var serverPath = Path.Combine(_env.WebRootPath, "images");
                    serverPath = Path.Combine(serverPath, filename);

                    using (FileStream SourceStream = System.IO.File.Open(serverPath, FileMode.OpenOrCreate))
                    {
                        await model.Logo.CopyToAsync(SourceStream);
                    }

                    taxicompany.LogoUrl = "/images/" + filename;
                }
                _context.Add(taxicompany);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var companyTaxi = await _context.CompanyTaxis.SingleOrDefaultAsync(m => m.Id == id);

            if (companyTaxi == null)
            {
                return(NotFound());
            }

            var model = new CompanyTaxiViewModel
            {
                Item          = companyTaxi,
                AddressOffice = companyTaxi.AddressOffice,
                PhoneCompany  = companyTaxi.PhoneCompany,
                Name          = companyTaxi.Name,
            };

            return(View(model));
        }
Beispiel #4
0
        public IActionResult Create()
        {
            var model = new CompanyTaxiViewModel();

            return(View(model));
        }