Ejemplo n.º 1
0
        public ActionResult Delete(Guid id)
        {
            try
            {
                var res        = _notice.GetNotice(id);
                var notice     = (Notice)res.Objeto;
                var IdCategory = notice.IdCategory;
                var response   = _notice.DeleteNotice(id);

                var pathImg = HttpContext.Server.MapPath("~/Assets/Storage/NoticesIMG/") + notice.Img;
                ArcolineHelper.DeleteFile(pathImg);

                if (response.Exito)
                {
                    TempData["Ok"] = response.Mensagem;
                }
                else
                {
                    TempData["Erro"] = response.Mensagem;
                }
                return(RedirectToAction("Details", "Category", new { id = IdCategory }));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Guid id, Notice editObject, HttpPostedFileBase upload)
        {
            try
            {
                if (upload != null)
                {
                    var res = _notice.GetNotice(id);
                    var notice_before_updated = (Notice)res.Objeto;

                    var pathImg = HttpContext.Server.MapPath("~/Assets/Storage/NoticesIMG/") + notice_before_updated.Img;
                    ArcolineHelper.DeleteFile(pathImg);

                    var extension = Path.GetExtension(upload.FileName);
                    var cvName    = "NOTICE" + DateTime.Now.ToString("yymmssfff") + extension;
                    upload.SaveAs(HttpContext.Server.MapPath("~/Assets/Storage/NoticesIMG/") + cvName);
                    editObject.Img = cvName;
                }

                ViewBag.Categories = new SelectList(_notice.CategoryCollection(), "IdCategory", "Name");
                var response = _notice.UpdateNotice(id, editObject);
                var notice   = (Notice)response.Objeto;

                if (response.Exito)
                {
                    TempData["Ok"] = response.Mensagem;
                }
                else
                {
                    TempData["Erro"] = response.Mensagem;
                }
                return(RedirectToAction("Details", "Category", new { id = notice.IdCategory }));
            }
            catch
            {
                return(View());
            }
        }