public void should_return_posts(
     [Frozen] IPostRepository repository,
     List<Post> posts,
     PostController controller)
 {
     repository.GetPosts().Returns(posts);
     controller.GetPosts(null).Posts.Should().Equal(posts);
 }
示例#2
0
 public static string GetFiles()
 {
     string type = "*.mp3";
     string[] files = Directory.GetFiles(FileUploader.sApplicationPath, type, SearchOption.TopDirectoryOnly);
     List<FileInfo> list = new List<FileInfo>();
     foreach (string file in files)
     {
         string fname = Path.GetFileNameWithoutExtension(file);
         string modify = File.GetLastWriteTime(file).ToString("yyyy-MM-dd");
         string artist = FileUtility.GetArtist(file);
         string filePath = "FileUploader.ashx?type=download&id=" + Path.GetFileName(file);
         int rank = Common.DBUitility.GetRecord(Path.GetFileName(file));
         list.Add(new FileInfo() { FileName = fname, FilePath = filePath, Modify = modify, Artist = artist, Rank = rank });
     }
     return new JavaScriptSerializer().Serialize(list);
 }
示例#3
0
		private static FileItem ProcessSingleFile(HttpContext context, List<string> urls, int i)
		{
			HttpPostedFile postedFile = context.Request.Files[i];
			byte[] filedata = new byte[postedFile.ContentLength];
			if (filedata.Length > 0)
			{
				postedFile.InputStream.Read(filedata, 0, postedFile.ContentLength);
				string filename = string.Concat(postedFile.FileName, "_", Guid.NewGuid().ToString(), postedFile.FileName.FileExt(true));
				string uploadDir = string.Concat(JoyConfig.Instance.RootUrl, "upload/");
				if (!Directory.Exists(context.Server.MapPath(uploadDir)))
				{
					Directory.CreateDirectory(context.Server.MapPath(uploadDir));
				}
				string fileurl = uploadDir + filename;
				string fullname = HttpContext.Current.Server.MapPath(fileurl);
				if (filedata.LongLength > 0)
				{
					File.WriteAllBytes(fullname, filedata);
					urls.Add(fileurl);
				}

				FileItem entity = new FileItem();
				entity.DisplayName = postedFile.FileName;
				entity.Filename = fileurl;
				UserItem user = Login.LoginUser;
				entity.UserId = user == null ? 0 : user.UserId;
				return entity;
			}
			return null;
		}
示例#4
0
		private static List<string> ProcessFiles(HttpContext context)
		{
			List<string> urls = new List<string>();
			var cidsel = new SqlObject();
			cidsel.Select("categoryid").From("tCategories").Where("iname", "like", "upload");

			string sql = cidsel.ToString();
			//var tb = D.DB.GetDataTable(sql);
			var list = D.DB.ExecuteValue(sql);
			if (list == null)
			{
				throw new CustomException("无法找到文件上传对应的类别。");
			}
			int cid = (int)list;
			for (int i = 0; i < context.Request.Files.Count; i++)
			{
				FileItem file = ProcessSingleFile(context, urls, i);
				if (file != null)
				{
					file.CategoryId = cid;
					var fins = new SqlObject();
					fins.InsertInto(file);
					sql = fins.ToString();
					D.DB.ExecuteNonQuery(sql);
				}
			}
			return urls;
		}
示例#5
0
文件: User.cs 项目: pwhe23/Myep
        public List<UserInfo> Query(int? userId)
        {
            var where = new List<string> { "1=1" };
            if (userId != null)
            {
                where.Add("[Id]=" + userId.Value);
            }

            return base.List<UserInfo>(@"
                SELECT [Users].Id AS UserId, Email
                FROM [Users]
                WHERE (" + string.Join(") AND (", where) + ")"
            );
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BasePage bp = new BasePage();

                //li_currentForm.Visible = false;
                //li_lastForm.Visible = false;
                //li_allforms.Visible = false;
                divlogin.Visible = true;
                divProfile.Visible = false;

                if (bp.ActiveUser != null)
                {
                    lblUserName.Text = bp.ActiveUser.Name;

                    if (bp.ActiveUser.Thumb != null)
                    {
                        string base64String = Convert.ToBase64String(bp.ActiveUser.Thumb, 0, bp.ActiveUser.Thumb.Length);
                        imgThumb.ImageUrl = String.Format("data:{0};base64,{1}", bp.ActiveUser.Mime, base64String);
                        imgThumb.Visible = true;
                    }
                }

                if (bp.ActiveUser != null && (bp.ActiveUser.UserTypeEnum == Lib.Enumerations.UserType.Entity || bp.ActiveUser.UserTypeEnum == Lib.Enumerations.UserType.Others))
                {
                    divlogin.Visible = false;
                    divProfile.Visible = true;
                    lblTitleHello.Text = String.Format("Olá {0}, seja bem-vindo!", bp.ActiveUser.Name);

                    //li_allforms.Visible = true;
                }

                if (bp.ActiveUser != null && bp.ActiveUser.UserTypeEnum == Lib.Enumerations.UserType.Entity && bp.ActiveUser.TermsOfUse == false && bp.ActiveUser.Network)
                {
                    if (!Request.Url.ToString().ToLower().Contains("user/profile.aspx"))
                    {
                        Response.Redirect("~/User/Profile.aspx");
                    }
                }

                if (bp.ActiveUser.UserTypeEnum == Lib.Enumerations.UserType.Site)
                {
                    List<string> paginasLiberadas = new List<string>();
                    paginasLiberadas.Add("account/login.aspx");
                    paginasLiberadas.Add("account/new.aspx");
                    paginasLiberadas.Add("default.aspx");

                    bool podeEntrar = false;

                    foreach (string urlPermitida in paginasLiberadas)
                    {
                        if (Request.Url.ToString().ToLower().Contains(urlPermitida.ToLower()))
                        {
                            podeEntrar = true;
                        }
                    }

                    if (!podeEntrar)
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                }
            }
        }
示例#7
0
文件: Intern.cs 项目: pwhe23/Myep
        public List<InternInfo> Query(int? internId, int? employerId)
        {
            var where = new List<string> {"1=1"};
            if (internId != null) where.Add("Intern.Id=" + internId);
            if (employerId.HasValue) where.Add("EmployerId=" + employerId);

            return base.List<InternInfo>(@"
                SELECT Intern.Id AS InternId, FirstName+' '+LastName AS FullName, EmployerId, Organization
                FROM Intern
                LEFT JOIN Employer ON Intern.EmployerId = Employer.Id
                WHERE (" + string.Join(") AND (", where) + ")"
            );
        }
示例#8
0
文件: Employer.cs 项目: pwhe23/Myep
        public List<EmployerInfo> Query(int? employerId)
        {
            var where = new List<string> { "1=1" };
            if (employerId != null)
            {
                where.Add("[Id]=" + employerId.Value);
            }

            return base.List<EmployerInfo>(@"
                SELECT Employer.Id AS EmployerId, Organization, ContactFirstName+' '+ContactLastName AS ContactName, ISNULL(Positions,0) AS Available,
                    (SELECT COUNT(*) FROM Intern WHERE EmployerId=Employer.Id) AS Filled
                FROM Employer
                WHERE (" + string.Join(") AND (", where) + ")"
            );
        }
        protected bool canShowSubmitButton(DataTableCollection tables, out List<string> notAnsweredQuestions, out List<string> incorrectAnsweredQuestions)
        {
            notAnsweredQuestions = new List<string>();
            incorrectAnsweredQuestions = new List<string>();

            List<String> AcceptedAnswers = new List<string>();
            AcceptedAnswers.Add("n/a");
            AcceptedAnswers.Add("0");
            AcceptedAnswers.Add("0.5");
            AcceptedAnswers.Add("0,5");
            AcceptedAnswers.Add("1");
            AcceptedAnswers.Add("1.0");
            AcceptedAnswers.Add("1,0");

            foreach (DataTable table in tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    if (row[4].ToString() == "P")
                    {
                        if (String.IsNullOrEmpty(row[2].ToString()))
                        {
                            notAnsweredQuestions.Add(row[0] + " - " + row[1]);
                        }
                        else
                        {
                            if (!AcceptedAnswers.Contains(row[2].ToString()))
                            {
                                incorrectAnsweredQuestions.Add(row[0] + " - " + row[1]);
                            }
                        }
                    }
                }
            }

            if (notAnsweredQuestions.Count > 0 || incorrectAnsweredQuestions.Count > 0)
            {
                return false;
            }

            return true;
        }
        /// <summary>
        /// Retorna uma lista de objetos do tipo UOL.PagSeguro.Produto para atualização de estoque
        /// </summary>
        /// <param name="numItens"></param>
        /// <returns></returns>
        private List<UOL.PagSeguro.Produto> RetornaListaProdutos(int numItens)
        {
            List<UOL.PagSeguro.Produto> listaProdutos = new List<UOL.PagSeguro.Produto>();

            for (int i = 0; i < numItens; i++)
            {
                UOL.PagSeguro.Produto p = new UOL.PagSeguro.Produto();
                p.Codigo = Request.Params[string.Format("ProdID_{0}", i + 1)];
                p.Quantidade = Convert.ToInt32(Request.Params[string.Format("ProdQuantidade_{0}", i + 1)]);

                listaProdutos.Add(p);
            }

            return listaProdutos;
        }