Esempio n. 1
0
        public async Task<IActionResult> Edit(TagViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Can we just update DB without fetching first, need ideas, also concurrency check needs to be done
                var dbModel = await Db.Tags.FirstAsync(d => d.Id == model.Id);
                Mapper.Map(model, dbModel, d => new { d.Name}); // Map only specific fields

                dbModel.ModifiedOn = DateTime.Now;
                dbModel.ModifiedBy = AppSession.AppUserId;

                // Need to fix ConcurrencyStamp check
                //Db.Entry(dbModel).OriginalValues["ConcurrencyStamp"] = model.ConcurrencyStamp;
                Db.Update(dbModel);
                await Db.SaveChangesAsync();

                //TempData.Success("Tag was successfully saved!");
                return RedirectToAction("Index");
            }
            //TempData.Danger("Tag was not saved! Please check errors.");

            ViewBag.Title = "Edit";
            return View("Add", model);
        }
Esempio n. 2
0
 public IActionResult Add()
 {
     var model = new TagViewModel();
     ViewBag.Title = "Add";
     return View(model);
 }
Esempio n. 3
0
        public async Task<IActionResult> Delete(TagViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Can we just update DB without fetching first, need ideas, also concurrency check needs to be done
                var dbModel = await Db.Tags.SingleOrDefaultAsync(c => c.Id == model.Id);
                if (dbModel == null) return HttpNotFound();

                // Need to fix RowStamp check
                //Db.Entry(dbModel).OriginalValues["RowStamp"] = model.RowStamp;
                Db.Tags.Remove(dbModel);
                await Db.SaveChangesAsync();

                //TempData.Success("Tag was successfully deleted!");
                return RedirectToAction("Index");
            }
            //TempData.Danger("Tag was not deleted! Please check errors.");

            ViewBag.Title = "Delete";
            return View(model);
        }
Esempio n. 4
0
        public async Task<IActionResult> Add(TagViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newModel = Mapper.Map(model, new Tag(), m => new { m.Name });

                newModel.CreatedOn = DateTime.Now;
                newModel.CreatedBy = AppSession.AppUserId;

                Db.Tags.Add(newModel);
                await Db.SaveChangesAsync();

                //TempData.Success("Tag was successfully saved!");
                return RedirectToAction("Index");
            }

            ViewBag.Title = "Add";
            return View(model);
        }