Beispiel #1
0
        public async Task <IActionResult> Postimi([Bind("IdPiktura,UrlPath,TitulliPiktures,ID_Useri,Pershkrimi,Karakteristikat,DataPostimit,Ekspozitat,LLojiPiktures,CmimiPiktures,Disponueshmeria,Shporta")] Pikturat pikturat, IFormFile file)
        {
            //FileUpload
            if (file != null && file.Length > 0)
            {
                var imagePath  = @"\Upload\Images\Pikturat\";
                var uploadPath = _env.WebRootPath + imagePath;

                //Create Directory
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }

                //Create Uniq file name
                var    uniqFileName = Guid.NewGuid().ToString();
                var    filename     = Path.GetFileName(uniqFileName + "." + file.FileName.Split(".")[1].ToLower());
                string fullPath     = uploadPath + filename;


                var filePath = @".." + Path.Combine(imagePath, filename);

                using (var fileStream = new FileStream(fullPath, FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }

                //urlPathi i piktures
                pikturat.UrlPath = filePath;
            }


            //id e uzerit te tabelen e pikutrave
            var user = await _userManager.GetUserAsync(User);

            pikturat.ID_Useri = user.Id;

            DateTime localDate = DateTime.Now;

            pikturat.DataPostimit = localDate;


            if (!TryValidateModel(pikturat, nameof(pikturat)))
            {
                _context.Add(pikturat);
                await _context.SaveChangesAsync();
            }


            return(RedirectToAction(nameof(PostimiC)));
        }
Beispiel #2
0
        public async Task <IActionResult> Kritika([Bind("Id_Kritika,Id_Useri,Id_Piktura,TekstiKritikes")] Kritikat kritikat)
        {
            if (kritikat.TekstiKritikes == null)
            {
                return(RedirectToAction(nameof(Pikturat)));
            }
            else
            {
                kritikat.Id_Useri = User.Identity.Name;

                if (!TryValidateModel(kritikat))
                {
                    _context.Add(kritikat);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Kritika)));
                }

                return(RedirectToAction(nameof(Pikturat)));
            }
        }