Esempio n. 1
0
        public async Task<ActionResult> Create(NoteViewModel noteViewModel)
        {
            if (ModelState.IsValid)
            {
                Note note = Mapper.Map<NoteViewModel, Note>(noteViewModel);
                _noteService.AddNote(note);
                await _noteService.CommitAsync();
                TempData["StatusBarInfo"] = new StatusBarInfo
                {
                    Message = "Successfully created.",
                    Type = StatusBarInfo.StatusBarType.Success
                };

                return RedirectToAction("Index");
            }

            return View(noteViewModel);
        }
Esempio n. 2
0
        public async Task<ActionResult> Edit(NoteViewModel noteViewModel)
        {
            if (ModelState.IsValid)
            {
                Note note = Mapper.Map<NoteViewModel, Note>(noteViewModel);

                if (_noteService.UpdateNote(note))
                {
                    await _noteService.CommitAsync();
                    TempData["StatusBarInfo"] = new StatusBarInfo
                    {
                        Message = "Successfully updated.",
                        Type = StatusBarInfo.StatusBarType.Success
                    };
                }
                else 
                {
                    TempData["StatusBarInfo"] = new StatusBarInfo
                    {
                        Message = "Unauthorized actions detected.",
                        Type = StatusBarInfo.StatusBarType.Warning
                    };
                }

                return RedirectToAction("Index");
            }

            return View(noteViewModel);
        }