Esempio n. 1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Title,Url")] Adverties adverties, HttpPostedFileBase Image)
        {
            db.Entry(adverties).State = EntityState.Modified;
            if (Image != null)
            {
                var _Bytes = new byte[Image.ContentLength];
                Image.InputStream.Read(_Bytes, 0, Image.ContentLength);
                adverties.Image = _Bytes;
            }
            else
            {
                db.Entry(adverties).Property(x => x.Image).IsModified = false;
            }
            if (ModelState.IsValid)
            {
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            if (Request.IsAjaxRequest())
            {
                return(PartialView(adverties));
            }
            return(View(adverties));
        }
Esempio n. 2
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Adverties adverties = await db.Adverties.FindAsync(id);

            db.Adverties.Remove(adverties);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        // GET: Adverties/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Adverties adverties = await db.Adverties.FindAsync(id);

            if (adverties == null)
            {
                return(HttpNotFound());
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView(adverties));
            }
            return(View(adverties));
        }
Esempio n. 4
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Title,Url")] Adverties adverties, HttpPostedFileBase Image)
        {
            var _Bytes = new byte[Image.ContentLength];

            Image.InputStream.Read(_Bytes, 0, Image.ContentLength);

            adverties.Image = _Bytes;

            if (ModelState.IsValid)
            {
                db.Adverties.Add(adverties);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(adverties));
            }
            return(View(adverties));
        }