Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Company_Name,Role_Name,Description,From,To,ImageFile")] Experience_Ar experience_Ar)
        {
            if (ModelState.IsValid)
            {
                //save image to wwwroot/Images/MyProjectsEn
                string wwwRootPath = _hostEnvironment.WebRootPath;
                string fileName    = Path.GetFileNameWithoutExtension(experience_Ar.ImageFile.FileName);
                string extension   = Path.GetExtension(experience_Ar.ImageFile.FileName);
                fileName = fileName + DateTime.Now.ToString("yymmssff") + extension;
                experience_Ar.ImageName = fileName;
                string path = Path.Combine(wwwRootPath + "/Images/Experience_Ar/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await experience_Ar.ImageFile.CopyToAsync(fileStream);
                }


                //insert record
                _context.Add(experience_Ar);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(experience_Ar));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int?id, Experience_Ar experience_Ar, IFormFile file)
        {
            if (id == null)

            {
                return(NotFound());
            }

            Experience_Ar experience_Ar2 = await _context.Experience_Ar.Where(x => x.Id == id).FirstOrDefaultAsync();



            if (experience_Ar2 == null)

            {
                return(NotFound());
            }

            if (file != null || file.Length != 0)

            {
                string filename = System.Guid.NewGuid().ToString() + ".jpg";

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Images/Experience_Ar", filename);



                using (var stream = new FileStream(path, FileMode.Create))

                {
                    await file.CopyToAsync(stream);
                }



                experience_Ar2.ImageName = filename;
            }

            experience_Ar2.Company_Name = experience_Ar.Company_Name;
            experience_Ar2.Role_Name    = experience_Ar.Role_Name;
            experience_Ar2.Description  = experience_Ar.Description;
            experience_Ar2.From         = experience_Ar.From;
            experience_Ar2.To           = experience_Ar.To;



            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int?id)

        {
            if (id == null)

            {
                return(NotFound());
            }

            Experience_Ar experience_Ar2 = await _context.Experience_Ar.Where(x => x.Id == id).FirstOrDefaultAsync();

            if (experience_Ar2 == null)

            {
                return(NotFound());
            }



            return(View(experience_Ar2));
        }