Ejemplo n.º 1
0
        public async Task <ActionResult> Edit([Bind(Include = "Category,CategoryLanguage,Language")] CrudCategory ec)
        {
            if (ModelState.IsValid)
            {
                ec.Category.LastEditTime    = DateTime.Now;
                ec.Category.LastEditUser    = User.Identity.GetUserId();
                db.Entry(ec.Category).State = EntityState.Modified;
                await db.SaveChangesAsync();

                foreach (var m in ec.CategoryLanguage)
                {
                    db.Entry(m.Value).State = EntityState.Modified;
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(ec));
        }
Ejemplo n.º 2
0
        // GET: Manage/Categories/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var category = await db.Category.FindAsync(id);

            if (category == null)
            {
                return(HttpNotFound());
            }


            var categorylanguage = await(from cl in db.CategoryLanguage
                                         where cl.CategoryId == category.Id
                                         select cl).ToListAsync();

            var cld = new Dictionary <string, CategoryLanguage>()
            {
            };

            foreach (var m in categorylanguage)
            {
                var langcode = await(from lc in db.Language
                                     where lc.Id == m.LanguageId
                                     select lc).FirstOrDefaultAsync();

                cld.Add(langcode.Code, m);
            }

            var ec = new CrudCategory()
            {
                Category         = category,
                CategoryLanguage = cld
            };


            return(View(ec));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "Category,CategoryLanguage,Language")] CrudCategory ec)
        {
            if (ModelState.IsValid)
            {
                ec.Category.CreateTime = ec.Category.LastEditTime = DateTime.Now;
                ec.Category.CreateUser = ec.Category.LastEditUser = User.Identity.GetUserId();
                db.Category.Add(ec.Category);
                await db.SaveChangesAsync();

                foreach (var m in ec.CategoryLanguage)
                {
                    m.Value.CategoryId = ec.Category.Id;
                    db.CategoryLanguage.Add(m.Value);
                }
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(ec));
        }
Ejemplo n.º 4
0
        // GET: Manage/Categories/Create
        public ActionResult Create()
        {
            CrudCategory ec = new CrudCategory();

            return(View(ec));
        }