コード例 #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //    _context.Attach(JobPosition).State = EntityState.Modified;

            try
            {
                _jobPositionService.UpdateJobPosition(JobPosition);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JobPositionExists(JobPosition.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        public void JobPositionWithInvalidId_WhenUpdated_ThrowsExeption()
        {
            var service    = new JobPositionService(context);
            var updateData = new JobPosition {
                Name = "JobPosition"
            };

            var ex = Assert.Throws <ArgumentException>(() => service.UpdateJobPosition(1, updateData));

            Assert.That(ex.Message, Is.EqualTo("Invalid job position id. (Parameter 'id')"));
        }
コード例 #3
0
        public void JobPosition_CanBeUpdated()
        {
            context.JobPositions.Add(new JobPosition {
                Name = "JobPosition"
            });
            context.SaveChanges();
            var service    = new JobPositionService(context);
            var updateData = new JobPosition {
                Name = "JobPosition2"
            };

            var jobPosition       = service.UpdateJobPosition(1, updateData);
            var jobPositionRecord = context.JobPositions.Single(i => i.Name == "JobPosition2");

            Assert.AreEqual("JobPosition2", jobPosition.Name);
            Assert.AreEqual("JobPosition2", jobPositionRecord.Name);
        }