Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(Announ ann)
        {
            db.Entry(ann).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(RedirectToAction("GetUserAnns"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit(string id)
        {
            Announ ann = await db.Announs.FindAsync(Int32.Parse(id));

            if (ann != null)
            {
                return(View(ann));
            }
            else
            {
                return(View("Error", new string[] { "Объявление не найдено" }));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create(Announ ann)
        {
            if (ModelState.IsValid)
            {
                User cur_user = await Manager.FindByNameAsync(HttpContext.User.Identity.Name);

                cur_user.Announs.Add(ann);
                await Manager.UpdateAsync(cur_user);

                return(RedirectToAction("GetUserAnns"));
            }
            else
            {
                ModelState.AddModelError("", "Некорректные данные");
            }

            return(View(ann));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Delete([Required] string id)
        {
            if (ModelState.IsValid)
            {
                Announ ann = await db.Announs.Where(a => a.Id.ToString() == id).FirstOrDefaultAsync();

                if (ann != null)
                {
                    db.Announs.Remove(ann);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("GetUserAnns"));
                }
                else
                {
                    return(View("Error", new string[] { "Не удалось найти объявление" }));
                }
            }
            else
            {
                return(View("Error", new string[] { "Произошла ошибка" }));
            }
        }