Exemplo n.º 1
0
        public ActionResult Create(News news, HttpPostedFileBase mediaUrl)
        {
            if (mediaUrl == null)
            {
                ModelState.AddModelError("mediaUrl", "Şəkil seçilməyib!");
            }
            else
            {
                if (!mediaUrl.CheckImageType())
                {
                    ModelState.AddModelError("mediaUrl", "Şəkil uyğun deyil!");
                }
                if (!mediaUrl.CheckImageSize(5))
                {
                    ModelState.AddModelError("mediaUrl", "Şəklin ölçüsü uyğun deyil!");
                }
            }

            if (ModelState.IsValid)
            {
                news.MediaUrl = mediaUrl.SaveImage(Server.MapPath("~/Template/media"));

                db.News.Add(news);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }



            ViewBag.CategoryId = new SelectList(db.Category, "Id", "Name", news.CategoryId);
            return(View(news));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Email,Message,IsReady,CreationDate,CreatedId,ModifiedDate,ModifiedId,DeletedDate,DeletedId")] Contact contact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(contact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(contact));
 }
Exemplo n.º 3
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Category.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemplo n.º 4
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Info info = db.Info.Find(id);

            info.IsRead          = true;
            db.Entry(info).State = EntityState.Modified;
            db.SaveChanges();
            if (info == null)
            {
                return(HttpNotFound());
            }
            return(View(info));
        }
Exemplo n.º 5
0
        public ActionResult Contactx(Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contact.Add(contact);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(contact));
        }
        // GET: Admin/Contacts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                if (Request.IsAjaxRequest())
                {
                    return(Content(""));
                }

                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Contact contact = db.Contact.Find(id);

            if (contact == null)
            {
                if (Request.IsAjaxRequest())
                {
                    return(Content(""));
                }

                return(HttpNotFound());
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("~/Areas/Admin/Views/Contacts/Partial/_ContactPartial.cshtml", contact));
            }

            if (!contact.IsReady)
            {
                contact.IsReady         = true;
                contact.ModifiedDate    = DateTime.Now;
                db.Entry(contact).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(View(contact));
        }
Exemplo n.º 7
0
        public JsonResult SendMessage(int?id, string answer)
        {
            VizewDbContext db      = new VizewDbContext();
            Contact        contact = db.Contact.FirstOrDefault(p => p.Id == id);

            //if (contact == null)
            //{
            //    return HttpNotFound();
            //}
            contact.IsAnswered   = true;
            contact.AnsweredDate = DateTime.Now;
            contact.Answer       = answer;
            db.SaveChanges();
            return(Json(contact));
        }
Exemplo n.º 8
0
        public ActionResult Contact(Contact contact)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Message = "Boş xanaları doldurun.";
            }
            else
            {
                ViewBag.Message = "Mesaj göndərildi.";

                using (VizewDbContext db = new VizewDbContext())
                {
                    db.Contact.Add(contact);
                    db.SaveChanges();
                }
            }

            return(View());
        }
        public void OnException(ExceptionContext filterContext)
        {
            var area = "";//todo....

            var controller = (filterContext.RouteData.Values["controller"] ?? "").ToString();
            var action     = (filterContext.RouteData.Values["action"] ?? "").ToString();

            //səbəbkar erroru tapmaq
            while (filterContext.Exception.InnerException != null)
            {
                filterContext.Exception = filterContext.Exception.InnerException;
            }

            var model = new HandleErrorInfo(filterContext.Exception, controller, action);

            try
            {
                using (var db = new VizewDbContext())
                {
                    var entity = new ErrorHistory();
                    if (!string.IsNullOrWhiteSpace(area))
                    {
                        entity.AreaName = area;
                    }
                    if (!string.IsNullOrWhiteSpace(controller))
                    {
                        entity.ControllerName = controller;
                    }
                    if (!string.IsNullOrWhiteSpace(action))
                    {
                        entity.ActionName = action;
                    }

                    if (filterContext.Exception is HttpException)
                    {
                        entity.ErrorCode = (filterContext.Exception as HttpException).GetHttpCode();
                    }
                    else if (filterContext.Exception is SqlException)
                    {
                        entity.ErrorCode    = (filterContext.Exception as SqlException).Number;
                        entity.ErrorMessage = filterContext.Exception.Message;
                    }
                    else
                    {
                        entity.ErrorMessage = filterContext.Exception.Message;
                    }

                    db.ErrorHistory.Add(entity);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
            }

            filterContext.Result = new ViewResult
            {
                ViewName   = "~/Views/Shared/Error.cshtml",
                MasterName = "~/Views/Shared/_Layout.cshtml",
                ViewData   = new ViewDataDictionary <HandleErrorInfo>(model),
                TempData   = filterContext.Controller.TempData
            };

            filterContext.ExceptionHandled = true;
        }