Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("HelpfulLinkId,LinkUrl,LinkDescription,UserId")] HelpfulLink helpfulLink)
        {
            if (id != helpfulLink.HelpfulLinkId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Identity. Need this to pick up the UserId.
                    var User = await GetCurrentUserAsync();

                    helpfulLink.UserId = User.Id;
                    _context.Update(helpfulLink);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HelpfulLinkExists(helpfulLink.HelpfulLinkId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", helpfulLink.UserId);
            return(View(helpfulLink));
        }
Ejemplo n.º 2
0
        public Infrastructure.Data.Entities.HelpfulLinkVm Post(Infrastructure.Data.Entities.HelpfulLinkVm vm, string Userid)
        {
            using (var db = new LMISEntities())
            {
                try
                {
                    var id         = vm.HelpfulLinkID;
                    var checkExist = db.HelpfulLinks.Count(c => (c.HelpfulLinkURL == vm.HelpfulLinkURL || c.HelpfulLinkName == vm.HelpfulLinkName) && c.HelpfulLinkLanguage == vm.HelpfulLinkLanguage && c.HelpfulLinkID != vm.HelpfulLinkID && c.IsDeleted == null);
                    if (checkExist > 0)
                    {
                        return(null);
                    }
                    if (id > 0) //Update
                    {
                        var tr = db.HelpfulLinks
                                 .Where(r => r.IsDeleted == null && r.HelpfulLinkID == id)
                                 .ToList().Single();

                        tr.HelpfulLinkURL      = vm.HelpfulLinkURL;
                        tr.HelpfulLinkName     = vm.HelpfulLinkName;
                        tr.HelpfulLinkLanguage = vm.HelpfulLinkLanguage;
                        tr.GroupID             = vm.GroupID;
                        tr.UpdateUserID        = Userid;
                        tr.UpdateDate          = DateTime.UtcNow;
                    }
                    else //Insert
                    {
                        var tr = new HelpfulLink()
                        {
                            HelpfulLinkURL      = vm.HelpfulLinkURL,
                            HelpfulLinkName     = vm.HelpfulLinkName,
                            HelpfulLinkLanguage = vm.HelpfulLinkLanguage,
                            GroupID             = vm.GroupID,
                            PostUserID          = Userid,
                            PostDate            = DateTime.UtcNow
                        };

                        db.HelpfulLinks.Add(tr);
                        db.SaveChanges();
                        vm.HelpfulLinkID = tr.HelpfulLinkID;
                    }

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ExceptionDispatchInfo.Capture(ex).Throw();
                }


                return(vm);
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("HelpfulLinkId,LinkUrl,LinkDescription,UserId")] HelpfulLink helpfulLink)
        {
            if (ModelState.IsValid)
            {
                // Identity. Need this to pick up the UserId.
                var User = await GetCurrentUserAsync();

                helpfulLink.UserId = User.Id;
                _context.Add(helpfulLink);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", helpfulLink.UserId);
            return(View(helpfulLink));
        }
Ejemplo n.º 4
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            // Create the applcation users (2).
            modelBuilder.Entity <ApplicationUser>()
            .Property(u => u.EnrollDate)
            .HasDefaultValueSql("GETDATE()");

            ApplicationUser user = new ApplicationUser
            {
                FirstName          = "Admin",
                LastName           = "Admin",
                UserName           = "******",
                NormalizedUserName = "******",
                Email           = "*****@*****.**",
                NormalizedEmail = "*****@*****.**",
                EmailConfirmed  = true,
                LockoutEnabled  = false,
                SecurityStamp   = Guid.NewGuid().ToString("D"),
                EnrollDate      = new DateTime(2008, 10, 15)
            };
            var passwordHash = new PasswordHasher <ApplicationUser>();

            user.PasswordHash = passwordHash.HashPassword(user, "Admin8*");
            modelBuilder.Entity <ApplicationUser>().HasData(user);

            ApplicationUser user2 = new ApplicationUser
            {
                FirstName          = "Guest",
                LastName           = "Guest",
                UserName           = "******",
                NormalizedUserName = "******",
                Email           = "*****@*****.**",
                NormalizedEmail = "*****@*****.**",
                EmailConfirmed  = true,
                LockoutEnabled  = false,
                SecurityStamp   = Guid.NewGuid().ToString("D"),
                EnrollDate      = new DateTime(2010, 11, 10)
            };
            var passwordHash2 = new PasswordHasher <ApplicationUser>();

            user2.PasswordHash = passwordHash2.HashPassword(user2, "Admin10*");
            modelBuilder.Entity <ApplicationUser>().HasData(user2);

            /******************** PRINCIPLES ********************/
            var principles = new Principle[]
            {
                // SOLID
                new Principle
                {
                    PrincipleId          = 1,
                    PrincipleImage       = "~/Images/SOLID_Img.png",
                    PrincipleName        = "S.O.L.I.D.",
                    PrincipleDescription = "SOLID is an acronym for the first five object-oriented design(OOD) principles by Robert C. Martin. These principles, when combined together, make it easy for a programmer to develop software that are easy to maintain and extend, and are also a part of agile, an adaptive software development principle. [S]ingle Responsibility Principle, [O]pen/ Closed Principle, [L]iskov Substitution Principle, [I]ntegration Segregation Principle, [D]ependency Inversion Principle",
                    UserId = null
                },

                // OPP
                new Principle
                {
                    PrincipleId          = 2,
                    PrincipleImage       = "~/Images/OOP_Img.png",
                    PrincipleName        = "O.O.P.",
                    PrincipleDescription = "Object Oriented Programming(OOP) is a language model that is organized around objects rather than actions and data rather than logic. There are four pillars of OOP: Abstraction, Polymorphism, Inheritance, and Encapsulation. You can remember this mnemonic device - A.P.I.E., because pie is awesome!",
                    UserId = null
                },

                // SRP
                new Principle
                {
                    PrincipleId          = 3,
                    PrincipleImage       = "~/Images/AGILE_Img.png",
                    PrincipleName        = "Agile",
                    PrincipleDescription = "There are four values derived from the Agile Manifesto: Individuals and Interactions Over Processes and Tools, Working Software Over Comprehensive Documentation, Customer Collaboration Over Contract Negotiation, Responding to Change Over Following a Plan.",
                    UserId = null
                }
            };

            modelBuilder.Entity <Principle>().HasData(principles);

            /******************** WHITEBOARD ********************/

            var whiteboards = new Whiteboard[]
            {
                // Median of Arrays
                new Whiteboard
                {
                    WhiteboardId          = 1,
                    WhiteboardImage       = "~/Images/MedianArrays_Img.png",
                    WhiteboardName        = "Median of Arrays",
                    WhiteboardDescription = "Find the median of two sorted arrays.",
                    UserId = null
                },
                // Fizz Buzz
                new Whiteboard
                {
                    WhiteboardId          = 2,
                    WhiteboardImage       = "~/Images/FizzBuzz_Img.png",
                    WhiteboardName        = "Fizz Buzz",
                    WhiteboardDescription = "Write a program that prints the numbers from 1 to 100 (here I have only written it for 1 to 15). But for multiples of three print 'Fizz' instead of the number and for the multiples of five print 'Buzz'. For numbers which are multiples of both three and five print 'FizzBuzz'.",
                    UserId = null
                }
            };

            modelBuilder.Entity <Whiteboard>().HasData(whiteboards);

            /******************** INTERVIEW QUESTIONS ********************/
            var intQuestions = new IntQuestion[]
            {
                // Question 1
                new IntQuestion {
                    IntQuestionId          = 1,
                    IntQuestionName        = "What are the two types of pop-ups?",
                    IntQuestionDescription = "Alert and Prompt.",
                    UserId = null
                },
                // Question 2
                new IntQuestion {
                    IntQuestionId          = 2,
                    IntQuestionName        = "What is the disadvantage of using : 'innerHTML'?",
                    IntQuestionDescription = "Content can be replaced anywhere.",
                    UserId = null
                },
                // Question 3
                new IntQuestion {
                    IntQuestionId          = 3,
                    IntQuestionName        = "What is the difference between var and let?",
                    IntQuestionDescription = "var is function-scoped and let is block-scoped.",
                    UserId = null
                },
                // Question 4
                new IntQuestion {
                    IntQuestionId          = 4,
                    IntQuestionName        = "What is the difference between '==' and '==='?",
                    IntQuestionDescription = "The first option == checks value equality, whereas === returns false, and checks both type and value equality.",
                    UserId = null
                }
            };

            modelBuilder.Entity <IntQuestion>().HasData(intQuestions);

            /******************** HELPFUL LINKS ********************/
            var helpfulLinks = new HelpfulLink[]
            {
                // Link 1
                new HelpfulLink {
                    HelpfulLinkId   = 1,
                    LinkUrl         = "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference",
                    LinkDescription = "JavaScript language Documentation",
                    UserId          = null
                },
                // Link 2
                new HelpfulLink {
                    HelpfulLinkId   = 2,
                    LinkUrl         = "https://docs.microsoft.com/en-us/dotnet/csharp/",
                    LinkDescription = "C# language Documentation",
                    UserId          = null
                },
                // Link 3
                new HelpfulLink {
                    HelpfulLinkId   = 3,
                    LinkUrl         = "https://reactjs.org/docs/getting-started.html",
                    LinkDescription = "React - Getting Started",
                    UserId          = null
                }
            };

            modelBuilder.Entity <HelpfulLink>().HasData(helpfulLinks);
        }