// GET: Control/Properities/Edit/5
        public async Task <IActionResult> Edit(int?id, bool status = true)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProperityViewModel model = new ProperityViewModel
            {
                Properity           = await _context.Properities.FirstOrDefaultAsync(x => x.Id == id),
                ProperityTranslates = _context.ProperityTranslates.Include("Language").Where(x => x.ProperityId == id).ToList()
            };

            if (model.Properity == null)
            {
                return(NotFound());
            }
            if (HttpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest")
            {
                model.Properity.Status = status;
                _context.SaveChanges();
                return(Json(new { res = true }));
            }
            return(View(model));
        }
        public async Task <IActionResult> Create(ProperityViewModel model)
        {
            if (ModelState.IsValid)
            {
                _context.Add(model.Properity);
                await _context.SaveChangesAsync();

                foreach (var properity in model.ProperityTranslates)
                {
                    properity.ProperityId = _context.Properities.FirstOrDefault(x => x.CreatedAt == model.Properity.CreatedAt).Id;
                    _context.Add(properity);
                    await _context.SaveChangesAsync();
                }
                TempData["Success"] = "Yeni Xüsusiyyət yaradıldl";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        // GET: Control/Properities/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            ProperityViewModel model = new ProperityViewModel
            {
                Properity           = await _context.Properities.FirstOrDefaultAsync(x => x.Id == id),
                ProperityTranslates = _context.ProperityTranslates.Include("Language").Where(x => x.ProperityId == id).ToList()
            };

            if (model.Properity == null)
            {
                return(NotFound());
            }

            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, ProperityViewModel model)
        {
            if (id != model.Properity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                foreach (var item in model.ProperityTranslates)
                {
                    item.ProperityId = id;
                    _context.ProperityTranslates.Update(item);
                }
                await _context.SaveChangesAsync();

                try
                {
                    model.Properity.ModifiedAt = DateTime.Now;
                    _context.Update(model.Properity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProperityExists(model.Properity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["Success"] = "Dəyişiklik uğurla başa çatdı";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }