Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Status,ReaderId,BookId")] ListNote listNote)
        {
            int ReaderId = listNote.ReaderId;                        //Get readerid for redirecttoaction
            var reader   = await _context.Readers.FindAsync(ReaderId);

            string ReaderName = reader.Login;
            //----------------------------------------------------------------
            var Listn = _context.ListNotes;   //Checks that it is no copy of connection

            foreach (var d in Listn)
            {
                if (d.BookId == ViewBag.BookId && d.ReaderId == ViewBag.ReaderId)
                {
                    return(RedirectToAction("Index", "ListNotes", new { id = ReaderId, name = ReaderName }));
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(listNote);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "ListNotes", new { id = ReaderId, name = ReaderName }));
            }
            ViewData["BookId"]   = new SelectList(_context.Books, "Id", "Name", listNote.BookId);
            ViewData["ReaderId"] = new SelectList(_context.Readers, "Id", "Login", listNote.ReaderId);
            return(RedirectToAction("Index", "ListNotes", new { id = ReaderId, name = ReaderName }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Status,ReaderId,BookId")] ListNote listNote)
        {
            if (id != listNote.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(listNote);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ListNoteExists(listNote.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]   = new SelectList(_context.Books, "Id", "Name", listNote.BookId);
            ViewData["ReaderId"] = new SelectList(_context.Readers, "Id", "Login", listNote.ReaderId);
            return(View(listNote));
        }
Ejemplo n.º 3
0
        private void btnListNote_Click(object sender, EventArgs e)
        {
            SlidePanel.Height = btnListNote.Height;
            SlidePanel.Top    = btnListNote.Top;

            ListNote ln = new ListNote();

            UserControlPanel.Controls.Add(ln);
            ln.Dock = DockStyle.Fill;
            ln.BringToFront();
        }
Ejemplo n.º 4
0
        public void ListNotePostShouldBeAddListNote()
        {
            // Arrange
            #region init_data
            var todoListCreatedTime = DateTime.Now;
            var todoListModel       = new ListNote()
            {
                Id          = 1,
                Title       = "List",
                CreatedDate = todoListCreatedTime
            };
            var toValue = new ListNoteValue()
            {
                Id          = 1,
                Title       = "List",
                CreatedDate = todoListCreatedTime
            };
            var toModel = new ListNote()
            {
                Id          = 1,
                Title       = "List",
                CreatedDate = todoListCreatedTime
            };
            var todoListValue = ListNoteValueBuilder
                                .CreateDefaultBuilder()
                                .Build();
            #endregion init_data

            #region dependecy
            var mockRepo      = new Mock <IRepository>();
            var mockMap       = new Mock <IMapper>();
            var mockValidator = new Mock <IValidationService>();
            mockMap.Setup(m => m.Map <ListNoteValue, ListNote>(It.IsAny <ListNoteValue>())).Returns(toModel);
            mockRepo.Setup(r => r.Add(It.IsAny <ListNote>())).ReturnsAsync(todoListModel);
            mockMap.Setup(m => m.Map <ListNote, ListNoteValue>(It.IsAny <ListNote>())).Returns(toValue);
            mockValidator.Setup(v => v.ValidateListNote(It.IsAny <ListNoteValue>(), "POST")).ReturnsAsync(new List <string>());
            var todoListController = new ListNoteController(mockRepo.Object, mockMap.Object, mockValidator.Object);
            #endregion dependency

            // Act
            var response = todoListController.Post(todoListValue).GetAwaiter().GetResult();

            // Assert
            response.Should().BeOfType <OkObjectResult>();
            var responseObjs = response as OkObjectResult;
            responseObjs.Value.Should().BeOfType <ListNoteValue>();
            var todoListValueResponse = (responseObjs.Value as ListNoteValue);

            responseObjs.StatusCode.Should().Be(200);
            todoListValueResponse.Should().Be(toValue);
        }
        public void AddLast(T element)
        {
            if (this.Count == 0)
            {
                this.head = this.tail = new ListNote(element);
            }
            else
            {
                var newTail = new ListNote(element);
                newTail.PreviousNode = this.tail;
                this.tail.NextNode   = newTail;
                this.tail            = newTail;
            }

            this.Count++;
        }
        public void AddFirst(T element)
        {
            if (this.Count == 0)
            {
                this.head = this.tail = new ListNote(element);
            }
            else
            {
                var newHead = new ListNote(element);
                newHead.NextNode       = this.head;
                this.head.PreviousNode = newHead;
                this.head = newHead;
            }

            this.Count++;
        }
        public T RemoveLast()
        {
            if (this.Count == 0)
            {
                throw new InvalidOperationException("The list is empty!");
            }

            T lastElement = this.tail.Value;

            this.tail = this.tail.PreviousNode;
            if (tail != null)
            {
                this.tail.NextNode = null;
            }
            else
            {
                this.head = null;
            }

            this.Count--;

            return(lastElement);
        }