关于完整解答Leo C.W博客中名为“我们公司的ASP.NET 笔试题,你觉得难度如何”的所有题目

简介:

关于完整解答Leo C.W博客中名为“我们公司的ASP.NET 笔试题,你觉得难度如何”的所有题目,请大家鉴定,不足之处,敬请指教!

第1到3题解答如下:

复制代码
    public enum QuestionType
    {
        Text = 0,
        MultipleChoice = 1
    }

    public interface IQuestion
    {
        string Title { get; set; }
        QuestionType Category { get; }
string GetAnswer(); }
public abstract class QuestionBase : IQuestion { public string Title { get; set; } public abstract QuestionType Category { get; } public virtual string GetAnswer() { return "默认答案"; } } public class TextQuestion : QuestionBase { public override QuestionType Category { get { return QuestionType.Text; } } public override string GetAnswer() { return "文本答案"; } } public class MultipleChoiceQuestion : QuestionBase { public override QuestionType Category { get { return QuestionType.MultipleChoice; } } public override string GetAnswer() { return "单选答案"; } }
复制代码

 

第4题:

复制代码
    public class Product
    {
        public string Name { get; set; }
        public string IsDeleted { get; set; }
    }

    public static class ProductExtension
    {
        public static IQueryable<Product> WhereNotDeleted(this IQueryable<Product> query)
        {
            return query.Where(p => p.IsDeleted != "");
        }
    }

    public class ProductService
    {
        public List<Product> GetActiveProducts(IQueryable<Product> query)
        {
            return query.WhereNotDeleted().ToList();
        }
    }
复制代码

第5

复制代码
select T1.Name,T2.[Year],T2.[Month],T2.InCome from [User] as T1 inner join
(select UserId,[Year],[Month],COUNT(Amount) AS InCome from InCome group by UserId,[Year],[Month]) as T2
on T1.Id=T2.UserId
order by T2.UserId,T2.[Year],T2.[Month]

复制代码
select T1.Name,T2.[Year],T2.[Month],COUNT(T2.Amount) AS InCome from [User] as T1 
inner join InCome as T2 on T1.Id=T2.UserId
group by T1.Name,T2.[Year],T2.[Month] order by T1.Name,T2.[Year],T2.[Month]

 

第6题:

复制代码
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public class Income
    {
        public int Id { get; set; }
        public int UserId { get; set; }
        public decimal Amount { get; set; }
        public int Year { get; set; }
        public int Month { get; set; }
    }

    public class UserIncomeDto
    {
        public string Name { get; set; }
        public int Year { get; set; }
        public int Month { get; set; }
        public decimal Income { get; set; }
    }

    public class UserIncomeService
    {
        public List<UserIncomeDto> GetUserIncomeDtos(IQueryable<User> users, IQueryable<Income> incomes)
        {
            var resultList = (from u in users
                          join newic in
                              (from ic in incomes
                               group ic by new { ic.UserId, ic.Year, ic.Month } into gp
                               select new { gp.Key, InCome = gp.Sum(g => g.Amount) })
                              on u.Id equals newic.Key.UserId
                    orderby newic.Key
                    select new UserIncomeDto() { Name = u.Name, Year = newic.Key.Year, Month = newic.Key.Month, Income = newic.InCome }).ToList();

            return resultList;                             
        }
    }
复制代码

第7

改HTML:

<form action="/admin/mobile/user/login" method="POST">
    <input type="text" placeholder="username" name="username" />
    <input type="password" placeholder="password" name="password" />
    <input type="submit" value="login" />
</form>

改路由:

            routes.MapRoute("UserLogin",
                            "~/admin/mobile/{controller}/{action}",
                            new { controller = "User", action = "Login" });

第8题:

复制代码
    public class Product1
    {
        public string Name { get; set; }
        public string Description { get; set; }

        public void Validate1()
        {
            if (string.IsNullOrEmpty(this.Name))
            {
                throw new Exception("please enter a name for the product");
            }
            if (string.IsNullOrEmpty(this.Description))
            {
                throw new Exception("product description is required");
            }
        }

        public void Validate2()
        {
            this.Require(x => x.Name, "please enter a name for the product");
            this.Require(x => x.Description, "product description is required");
        }

        public void Require(Expression<Func<Product1, string>> expression, string errorMessage)
        {
            Func<Product1, string> func = expression.Compile();

            if (string.IsNullOrEmpty(func(this)))
            {
                throw new Exception(errorMessage);
            }
        }
    }

    public class TestProgram
    {
        public static void Main()
        {
            Product1 product1 = new Product1();
            try
            {
                product1.Validate2();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
    }
复制代码

 更多IT相关的文章,欢迎光临我的个人网站:http://www.zuowenjun.cn/

本文转自 梦在旅途 博客园博客,原文链接: http://www.cnblogs.com/zuowj/p/4118404.html ,如需转载请自行联系原作者

相关文章
|
3月前
|
开发框架 前端开发 小程序
分享46个ASP.NET博客程序源码,总有一款适合您
分享46个ASP.NET博客程序源码,总有一款适合您
24 0
|
前端开发 .NET C++
艾伟_转载:ASP.NET MVC 2博客系列
过去的6个月里,ASP.NET开发团队一直不断地发布了ASP.NET MVC 2的预览版,然后是beta版,现在则是RC(最终版的候选版)。 鉴于最终版的发布也不太远了,我想该是开始一个含多个部分的ASP.NET MVC 2 新博客系列的时候了,该系列旨在讨论新的特性以及该如何充分利用它们。
876 0
|
Web App开发 前端开发 .NET
艾伟_转载:ASP.NET MVC 2博客系列之一:强类型HTML辅助方法
这是我针对即将发布的ASP.NET MVC 2所撰写的贴子系列的第一篇,这个博客贴子将讨论 ASP.NET MVC 2中新加的强类型HTML辅助方法。 现有的HTML辅助方法 ASP.NET MVC 1中发布了一套HTML辅助方法,可以用来在视图模板中帮助生成HTML界面。
859 0
|
关系型数据库 .NET 数据库
牛腩学ASP.NET CORE做博客(视频)
牛腩学习ASP.NET CORE做的项目,边学边做。 目录: 01-dotnetcore网站部署到centos7系统上(时长 2:03:16) 02-前期准备及项目搭建 (时长:0:23:35) 03-数据库设计及Dapper使用(时长:0:50:47) 04-后台博客文章增删改(时...
1164 0
|
3月前
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
42 0