예제 #1
0
        public ActionResult Create([Bind(Include = "Id,Adi,GrupId,CozunurlukId,Marka,BoyutuInc,AlimTarihi,BaslamaTarihi,SeriNu,Aciklama")] Monitor monitor)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);
            var user   = _userService.GetByUserName(User.Identity.Name);

            //monitor.UserId = user.Id;
            if (ModelState.IsValid)
            {
                _monitorService.Insert(monitor);
                TempData["EklenenCihaz"] = monitor.SeriNu;

                var cihazler = new int[1]
                {
                    monitor.Id
                };

                return(RedirectToAction("Index"));
            }
            else
            {
                var errorText = "";
                foreach (var item in errors)
                {
                    errorText = errorText + " " + item;
                }
                TempData["MessageDanger"] = "ERROR: Modelstate is invalid, " + errorText.ToString();
            }
            var gruplar = _grupService.GetList();

            ViewBag.GrupId = new SelectList(gruplar, "Id", "Adi");
            var cozunurlukler = _cozunurlukService.GetList();

            ViewBag.CozunurlukId = new SelectList(cozunurlukler, "Id", "Adi");

            return(View(monitor));
        }