public async Task <IActionResult> Edit(int id, [Bind("IntQuestionId,IntQuestionName,IntQuestionDescription,UserId")] IntQuestion intQuestion)
        {
            if (id != intQuestion.IntQuestionId)
            {
                return(NotFound());
            }

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

                    intQuestion.UserId = User.Id;
                    _context.Update(intQuestion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IntQuestionExists(intQuestion.IntQuestionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            //ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", intQuestion.UserId);
            return(View(intQuestion));
        }
        public object MapItem(List <IDomainInfoViewModels> list, object Tmodel)
        {
            try
            {
                Type myType = Tmodel.GetType();

                IList <PropertyInfo> props = new List <PropertyInfo>(myType.GetProperties());
                foreach (var domainItem in list)
                {
                    foreach (PropertyInfo property in props)
                    {
                        if (domainItem.DomainInformation.PropertyMapping == property.Name)
                        {
                            switch (domainItem.DomainType.TypeName)
                            {
                            case "StringType":
                                TextQuestion txtQuestion = (TextQuestion)domainItem.Question;
                                property.SetValue(Tmodel, txtQuestion.Value);
                                break;

                            case "BoolType":
                                BoolQuestion boolQuestion = (BoolQuestion)domainItem.Question;
                                property.SetValue(Tmodel, boolQuestion.Value);
                                break;

                            case "IntType":
                                IntQuestion intQuestion = (IntQuestion)domainItem.Question;
                                property.SetValue(Tmodel, intQuestion.Value);
                                break;

                            case "DateTimeType":
                                DateTimeQuestion dateTimeQuestion = (DateTimeQuestion)domainItem.Question;
                                property.SetValue(Tmodel, dateTimeQuestion.Value);
                                break;

                            case "DropdownType":
                                DropdownQuestion dropDownQuestion = (DropdownQuestion)domainItem.Question;
                                property.SetValue(Tmodel, dropDownQuestion.Value);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)

            {
                var x = ex.Message;
            }


            return(Tmodel);
        }
Exemple #3
0
        /// <summary>
        /// 我要提问
        /// </summary>
        /// <param name="qid"></param>
        /// <returns></returns>
        public ActionResult AddQ(int qid = 0)
        {
            ViewBag.integral = IntegrationManager.Instence.GetUserTotalIntegral(CurrentUser.UserId);
            //给出一级分类
            ViewBag.firstSorts = qaService.GetFirstSorts(CurrentTenant.TenantId);

            IntQuestion question;

            question = qid == 0 ? new IntQuestion() : qaService.GetQuestionById(qid);
            if (question == null)
            {
                question = new IntQuestion();
            }
            return(View(question));
        }
        public async Task <IActionResult> Create([Bind("IntQuestionId,IntQuestionName,IntQuestionDescription,UserId")] IntQuestion intQuestion)
        {
            if (ModelState.IsValid)
            {
                // Identity. Need this to pick up the UserId.
                var User = await GetCurrentUserAsync();

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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", intQuestion.UserId);
            return(View(intQuestion));
        }
Exemple #5
0
        /// <summary>
        /// 删除问题
        /// </summary>
        /// <param name="question"></param>
        /// <returns></returns>
        public int DeleteQuestion(IntQuestion question)
        {
            if (question.SortId != 0)
            {
                var allsorts = GetAllSorts(question.TenantId);

                QuestionSort sort = allsorts.First(p => p.SortId == question.SortId);
                while (sort.ParentId != 0)
                {
                    sort = allsorts.First(p => p.SortId == sort.ParentId);
                }
                _dataAccess.UpdateFieldCalc("Int_QuestionSort", "QuestionCount", "QuestionCount-1", "SortId=" + sort.SortId);
            }
            //删除索引
            SetQuestionFullSearch(question.QuestionId);
            return(_dataAccess.UpdateField("Int_Question", "IsDelete", "1", "QuestionId=" + question.QuestionId));
        }
Exemple #6
0
        /// <summary>
        /// 新增问题
        /// </summary>
        /// <param name="question"></param>
        /// <returns></returns>
        public int AddQuestion(IntQuestion question)
        {
            if (question.SortId != 0)
            {
                var allsorts = GetAllSorts(question.TenantId);

                QuestionSort sort = allsorts.First(p => p.SortId == question.SortId);
                while (sort.ParentId != 0)
                {
                    sort = allsorts.First(p => p.SortId == sort.ParentId);
                }
                _dataAccess.UpdateFieldCalc("Int_QuestionSort", "QuestionCount", "QuestionCount+1", "SortId=" + sort.SortId);
            }
            var id = _dataAccess.AddEntity(question);

            //全文检索
            SetQuestionFullSearch(question.QuestionId);

            return(id);
        }
        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);
        }
        public async Task <DomainViewModel> GetQuestionSet(int groupId)
        {
            DomainViewModel model = new DomainViewModel();

            var selectedDomainGroup = await _groupRepo.GetAsync(groupId);

            model.DomainGroup = selectedDomainGroup;

            var SelectedDomainInformation = await _informationRepo.GetAllByGroupIdAsync(selectedDomainGroup.Id);

            List <IDomainInfoViewModels> domainInfoViewModel = new List <IDomainInfoViewModels>();


            foreach (var domainInformation in SelectedDomainInformation)
            {
                DomainInfoViewModel infoModel = new DomainInfoViewModel
                {
                    DomainInformation = domainInformation,
                    DomainType        = await _typeRepo.GetAsync(domainInformation.TypeId),
                };

                if (infoModel.DomainType.TypeName == CustomType.StringType.ToString())
                {
                    IQuestion textQuestion = new TextQuestion
                    {
                        Text          = infoModel.DomainInformation.Title,
                        Order         = infoModel.DomainInformation.Order,
                        HasValidation = infoModel.DomainInformation.HasValidation
                    };
                    infoModel.Question = textQuestion;
                }
                else if (infoModel.DomainType.TypeName == CustomType.BoolType.ToString())
                {
                    IQuestion boolQuestion = new BoolQuestion
                    {
                        Text          = infoModel.DomainInformation.Title,
                        Order         = infoModel.DomainInformation.Order,
                        HasValidation = infoModel.DomainInformation.HasValidation
                    };
                    infoModel.Question = boolQuestion;
                }
                else if (infoModel.DomainType.TypeName == CustomType.IntType.ToString())
                {
                    IQuestion intQuestion = new IntQuestion
                    {
                        Text          = infoModel.DomainInformation.Title,
                        Order         = infoModel.DomainInformation.Order,
                        HasValidation = infoModel.DomainInformation.HasValidation
                    };
                    infoModel.Question = intQuestion;
                }
                else if (infoModel.DomainType.TypeName == CustomType.DateTimeType.ToString())
                {
                    IQuestion dateTimeQuestion = new DateTimeQuestion
                    {
                        Text          = infoModel.DomainInformation.Title,
                        Order         = infoModel.DomainInformation.Order,
                        HasValidation = infoModel.DomainInformation.HasValidation
                    };
                    infoModel.Question = dateTimeQuestion;
                }
                else if (infoModel.DomainType.TypeName == CustomType.DropdownType.ToString())
                {
                    IQuestion dropdownQuestion = new DropdownQuestion
                    {
                        Text          = infoModel.DomainInformation.Title,
                        Order         = infoModel.DomainInformation.Order,
                        HasValidation = infoModel.DomainInformation.HasValidation,
                        Values        = infoModel.DomainInformation.Arguments.Split(',').ToList()
                    };
                    infoModel.Question = dropdownQuestion;
                }

                domainInfoViewModel.Add(infoModel);
            }

            model.DomainInfoViewModels = domainInfoViewModel;


            return(model);
        }
Exemple #9
0
        /// <summary>
        /// 加载问题的图片
        /// </summary>
        /// <param name="question"></param>
        public void LoadQuestionImages(IntQuestion question)
        {
            var imgs = _dataAccess.GetList <IntQuestionImage>("QuestionId=" + question.QuestionId);

            question.Images.AddRange(imgs);
        }
Exemple #10
0
        public ActionResult SaveTopQ(string title, string content, string tags,
                                     int?answer, int?score, DateTime?expired, string answercontent, string questionImages)
        {
            var question = new IntQuestion();

            question.TenantId = CurrentTenant.TenantId;
            question.Title    = title;
            question.UserId   = CurrentUser.UserId;
            question.Question = content;
            question.Tags     = tags;
            if (Request.Files.Count > 0 && Request.Files["imgurl"] != null && Request.Files["imgurl"].ContentLength > 0)
            {
                var imgPath = SaveFile(Request.Files["imgurl"], "~/UploadFiles/IntQuestionImg/");
                question.ImageUrl = imgPath;
            }
            if (Request.Files.Count > 0 && Request.Files["frontImg"] != null && Request.Files["frontImg"].ContentLength > 0)
            {
                var imgPath = SaveFile(Request.Files["frontImg"], "~/UploadFiles/IntQuestionImg/");
                question.FrontImage = imgPath;
            }
            if (string.IsNullOrEmpty(question.FrontImage))
            {
                question.FrontImage = "~/themes/default/img/nopic.png";
            }
            question.Expired      = expired;
            question.SortId       = 0;
            question.AnswerUserId = answer.HasValue ? answer.Value : 0;
            question.Integration  = score.HasValue ? score.Value : 0;
            question.IsThematic   = 1;
            question.QuestionTime = DateTime.Now;
            question.IsHideName   = 0;

            qaService.AddQuestion(question);
            if (!string.IsNullOrEmpty(questionImages))
            {
                //添加图片
                dynamic imgs    = Newtonsoft.Json.JsonConvert.DeserializeObject(questionImages);
                var     qImages = new List <IntQuestionImage>();
                foreach (dynamic img in imgs)
                {
                    qImages.Add(new IntQuestionImage()
                    {
                        QuestionId = question.QuestionId,
                        BigPic     = img.bigpic,
                        SmallPic   = img.thumbpath
                    });
                }
                qaService.AddQuestionImages(qImages);
            }
            if (!string.IsNullOrEmpty(answercontent))
            {
                //默认答案设置为最佳答案
                var defanswer = new UserAnswer();
                defanswer.QuestionId    = question.QuestionId;
                defanswer.AnswerTime    = DateTime.Now;
                defanswer.AnswerContent = answercontent;
                defanswer.IsGood        = 1;
                defanswer.UserId        = CurrentUser.UserId;
                qaService.AddUserAnswer(defanswer);
                qaService.SetGoodAnswer(question.QuestionId, defanswer.AnswerId);
            }
            return(Json(new { result = 1, msg = RetechWing.LanguageResources.Common.SaveSuccess }, "text/html", JsonRequestBehavior.DenyGet));
        }
Exemple #11
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(IntQuestion model)
 {
     return(_dataAccess.UpdateEntity(model) > 0);
 }
Exemple #12
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(IntQuestion model)
 {
     return(_dataAccess.AddEntity(model));
 }
Exemple #13
0
        public ActionResult SaveQuestion(string title, string content, string tags, int sortId, int?answer, int?score, DateTime?expired, int ishide, string images)
        {
            //验证
            //1:验证积分是否够用
            if (score.HasValue)
            {
                var userTotalIntegral = IntegrationManager.Instence.GetUserTotalIntegral(CurrentUser.UserId);
                if (userTotalIntegral < score.Value)
                {
                    //积分不够了
                    return(Json(new { result = 0, msg = "积分不够了" }, JsonRequestBehavior.DenyGet));
                }
            }


            var question = new IntQuestion();

            question.TenantId = CurrentTenant.TenantId;
            question.Title    = title;
            question.UserId   = CurrentUser.UserId;
            question.Question = content;
            question.Tags     = tags;
            if (Request.Files.Count > 0 && Request.Files[0] != null && Request.Files[0].ContentLength > 0)
            {
                var imgPath = SaveFile(Request.Files[0], "~/UploadFiles/IntQuestionImg/");
                question.ImageUrl = imgPath;
            }

            if (expired.HasValue)
            {
                var dt = expired.Value;
                expired = new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59);
            }
            question.Expired      = expired;
            question.SortId       = sortId;
            question.AnswerUserId = answer.HasValue ? answer.Value : 0;
            question.Integration  = score.HasValue ? score.Value : 0;

            question.QuestionTime = DateTime.Now;
            question.IsHideName   = ishide;
            qaService.AddQuestion(question);
            if (!string.IsNullOrEmpty(images))
            {
                //添加图片
                dynamic imgs    = Newtonsoft.Json.JsonConvert.DeserializeObject(images);
                var     qImages = new List <IntQuestionImage>();
                foreach (dynamic img in imgs)
                {
                    qImages.Add(new IntQuestionImage()
                    {
                        QuestionId = question.QuestionId,
                        BigPic     = img.bigpic,
                        SmallPic   = img.thumbpath
                    });
                }
                qaService.AddQuestionImages(qImages);
            }

            if (question.Integration > 0)
            {
                //减积分
                IntegrationManager.Instence.AddIntegration(0, 0 - question.Integration, CurrentUser.UserId, CurrentTenant.TenantId, "PayAskQuestionAwards");
            }

            #region 积分
            BusinessCommon.Integration.IntegrationManager.Instence.FireIntegrationEvent(IntegrationEvents.Question,
                                                                                        CurrentUser.UserId, CurrentTenant.TenantId);

            #endregion

            return(Json(new { result = 1, msg = RetechWing.LanguageResources.Common.SaveSuccess }, JsonRequestBehavior.DenyGet));
        }