public BLResponse<Author> GetAuthors(BLRequest blRequest){

			return Client.Execute(proxy=>{
				var u= Authors.Get(proxy);
				var r = new BLResponse<Author>();
				if(!IsCayita(blRequest)) 
					r.Result=u;
				else
				{
					HtmlDiv div = new HtmlDiv( ){Name="Author"};

					var itag = new HtmlIcon(){
						Class="button-add icon-plus-sign",
						Name="Author"
					};

					div.AddHtmlTag(itag);

					div.AddHtmlTag(BuildAuthorGrid(u));

					HtmlDiv formDiv = new HtmlDiv(){Id="div-form-edit"};
					formDiv.Style.Hidden=true;

					var form = BuildAuthorForm();
					form.AddCssClass("span6");
					form.Title="Author's Data";
					formDiv.AddHtmlTag(form);
				
					r.Html= div.ToString()+formDiv.ToString();

				}
				return r;
			});
		}
		public BLResponse<Author>  SaveAuthor(SaveAuthor author, BLRequest blRequest){

			Client.Execute(proxy=>{

				if(author.Id==default(int)){
					Rules.AuthorRules.ValidateOnSave(author, Authors.Count(proxy));
					Authors.Post(proxy,author);
				}
				else{
					Rules.AuthorRules.ValidateOnSave(author);
					Authors.Put(proxy,author);
				}

			});

			var r = new BLResponse<Author>();
			if(!IsCayita(blRequest)) 
				r.Result.Add(author);
			else
			{
				var grid = BuildAuthorGrid(new List<Author>());
				var dr =grid.CreateRow(author);
				r.Html= dr.ToString();
			}
			return r;
		
		}
		public BLResponse<User>  SaveUser(SaveUser user, BLRequest blRequest){

			Client.Execute(proxy=>{

				if(user.Id==default(int)){
					Rules.UserRules.ValidateOnSave(user, Users.Count(proxy));
					Users.Post(proxy,user);
				}
				else{
					Rules.UserRules.ValidateOnSave(user);
					Users.Put(proxy,user);
				}

			});

			var r = new BLResponse<User>();
			if(!IsCayita(blRequest)) 
				r.Result.Add(user);
			else
			{
				var grid = BuildUserGrid(new List<User>());
				var dr =grid.CreateRow(user);
				r.Html= dr.ToString();
			}
			return r;
		
		}
		public BLResponse<Sale> SendSalesRepo(SendSales request, BLRequest blRequest){

			var res = new BLResponse<Sale>();

			var mailTarget = request.Email; //MailTarget(blRequest);

			var sales = GetSalesFromRepo(request, blRequest);

			var gsbv = (from g in sales group g by g.Vendor into r 
			select new SalesByVendor {
				Vendor=  r.Key, 
				Total= r.Sum(p=>p.Price)
			}).OrderByDescending(f=>f.Total).ToList();

			HtmlDiv div = new HtmlDiv();

			var gridSalesByVendor =BuildSalesByVendorGrid(gsbv, mailTarget);

			div.AddHtmlTag(gridSalesByVendor);
			div.AddHtmlTag( new HtmlLineBreak());

			foreach(var sv in gsbv ){
				div.AddHtmlTag(( BuildDetails(sv.Vendor, sales.Where(f=>f.Vendor== sv.Vendor).ToList(), mailTarget)));
				div.AddHtmlTag( new HtmlLineBreak());
			}

			if(mailTarget.IsNullOrEmpty()){
				res.Html= div.ToString();
				return res;
			}

			SendSalesRepoByMail(div, mailTarget);
			return res;
		}
Пример #5
0
		protected bool IsCayita (BLRequest request)
		{
			var httpReq= request.RequestContext.Get<IHttpRequest>();

			bool cayita=false;
			bool.TryParse(httpReq.QueryString["cayita"], out cayita);
			return cayita;
		}
		public BLResponse<Author> DeleteAuthor(DeleteAuthor author, BLRequest blRequest){

			Client.Execute(proxy=>{
				Authors.Destroy(proxy, author.Id);
			});

			var r = new BLResponse<Author>();
			if(IsCayita(blRequest)) 
				r.Html= "record deleted";
			return r;
		}
		public BLResponse<User> DeleteUser(DeleteUser user, BLRequest blRequest){

			Client.Execute(proxy=>{
				Users.Destroy(proxy, user.Id);
			});

			var r = new BLResponse<User>();
			if(IsCayita(blRequest)) 
				r.Html= "record deleted";
			return r;
		}
		public BLResponse<Sale> GetSales(GetSales request, BLRequest blRequest){
			var sales = GetSalesFromRepo(request, blRequest);

			var r = new BLResponse<Sale>();
			if( !IsCayita(blRequest))
			{
				r.Result= sales;
			}
			else
			{
				r.Html = BuildSalesGrid(sales).ToString();
			}
		
			return r;

		}
		public BLResponse<Author> GetAuthor(GetAuthor request, BLRequest blRequest){
			return Client.Execute(proxy=>{
				var u= Authors.FirstOrDefault(proxy, f=>f.Id==request.Id);
				if( u==default(Author))
					throw new BLException("Author not found. Id:'{0}'".Fmt(request.Id));

				var r = new BLResponse<Author>();
				if(!IsCayita(blRequest)) r.Result.Add(u);
				else
				{
					var grid = BuildAuthorGrid(new List<Author>());
					var dr =grid.CreateRow(u);
					r.Html= dr.ToString();
				}
				return r;
			});
		}
		public BLResponse<User> SendUserForm(UserForm request, BLRequest blRequest)
		{
			return new BLResponse<User>(){Html = BuildUserForm().ToString()};
		}
		List<Sale> GetSalesFromRepo(IHasVendor request, BLRequest blRequest){

			return Client.Execute(proxy=>{
				return request.Vendor.IsNullOrEmpty()?
					Sales.Get(proxy):
					Sales.Get(proxy, f=>f.Vendor==request.Vendor.Trim());
			});
		}