Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Title,Upload,Photo,Id,Content")] HomeHealth homeHelth)
        {
            if (homeHelth.Upload == null)
            {
                ModelState.AddModelError("Upload", "Şəkil məcburidir");
            }
            else
            {
                if (homeHelth.Upload.ContentType != "image/jpeg" && homeHelth.Upload.ContentType != "image/png" && homeHelth.Upload.ContentType != "image/gif")
                {
                    ModelState.AddModelError("Upload", "Siz yalnız png,jpg və ya gif faylı yükləyə bilərsiniz");
                }

                if (homeHelth.Upload.Length > 1048576)
                {
                    ModelState.AddModelError("Upload", "Fayl ölcüsu maximum 1MB ola bilər");
                }
            }
            if (ModelState.IsValid)
            {
                var fileName = _fileManager.Upload(homeHelth.Upload);
                homeHelth.Photo = fileName;

                _context.Add(homeHelth);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(homeHelth));
        }
Beispiel #2
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Home")
     {
         HomeHealth home = col.gameObject.GetComponent <HomeHealth>();
         home.HealthDecrease();
         Destroy(gameObject);
     }
     else if (col.tag == "Tower")
     {
         Pan pan = col.gameObject.GetComponent <Pan>();
         pan.Attack(gameObject);
     }
 }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Title,Upload,Photo,Id,Content")] HomeHealth homeHelth)
        {
            if (id != homeHelth.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (homeHelth.Upload != null)
                    {
                        if (homeHelth.Upload.ContentType != "image/jpeg" && homeHelth.Upload.ContentType != "image/png" && homeHelth.Upload.ContentType != "image/gif")
                        {
                            ModelState.AddModelError("Upload", "Siz yalnız png,jpg və ya gif faylı yükləyə bilərsiniz");
                            return(View(homeHelth));
                        }

                        if (homeHelth.Upload.Length > 1048576)
                        {
                            ModelState.AddModelError("Upload", "Fayl ölcüsu maximum 1MB ola bilər");
                            return(View(homeHelth));
                        }

                        var oldFile = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", homeHelth.Photo);
                        _fileManager.Delete(oldFile);

                        var fileName = _fileManager.Upload(homeHelth.Upload, "wwwroot/uploads");
                        homeHelth.Photo = fileName;
                    }

                    _context.Update(homeHelth);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HomeHealthExsist(homeHelth.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(homeHelth));
        }