public StandardResult <List <OrderView> > GetList(OrderSearch search = null) { Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true; var result = new StandardResult <List <OrderView> >(); using (var db = base.NewDB()) { StringBuilder sqlCommonText = new StringBuilder("select * from view_orders where 1=1"); if (search != null) { if (!string.IsNullOrWhiteSpace(search.Issue)) { sqlCommonText.Append(" and issue=@Issue"); } if (search.OrderType != 0) { sqlCommonText.Append(" and ORDER_TYPE=@OrderType"); } if (search.CustomerId != 0) { sqlCommonText.Append(" and CustomerId=@CustomerId"); } } var list = db.Query <OrderView>(sqlCommonText.ToString(), search); result.Body = list.ToList(); return(result); } }
public void ShouldCreateStudentWithError() { commandRegister = new StudentInputRegister() { CourseId = course.CourseId, Birthdate = DateTime.Now, FirstName = string.Empty, LastName = string.Empty, CPF = string.Empty, Email = string.Empty, Phone = string.Empty, Gender = string.Empty, Country = string.Empty, City = string.Empty, Address = string.Empty }; StandardResult result = (StandardResult)handler.Handle(commandRegister); Assert.IsFalse(result.IsValid); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Email" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "CPF" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "FirstName" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "LastName" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Telefone" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "City" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Country" && x.Value != null)); }
public void ShouldUpdateDisciplineWithSuccess() { StandardResult result = (StandardResult)handler.Handle(commandUpdate); var disciplineDB = _DREP.Get(discipline.Id); Assert.AreEqual(disciplineDB.Id, discipline.Id); }
private static StandardResult <string> EvaulateExpression(SimpleTableRow row, string expressionText) { if (expressionText == null) { return(StandardResult <string> .ReturnResult(null)); } var fieldSource = new FieldDataSource() { Row = row }; var expression = ExpressionCache.Compile(expressionText); var result = expression.Evaluate(new Context() { FieldSource = fieldSource }); if (result.IsError) { return(StandardResult <string> .ReturnError(result.String)); } if (!result.IsString) { return(StandardResult <string> .ReturnError("message processing error - expression evaulation did not result in a string")); } return(StandardResult <string> .ReturnResult(result.String)); }
public StandardResult Update(Customers model) { StandardResult result = new StandardResult(); using (var db = base.NewDB()) { try { string sqlCommandText = "Update t_customers set name=@Name,phone=@Phone,isdel=@IsDel,remarks=@Remarks where id=@Id"; if (db.Execute(sqlCommandText, model) > 0) { result.Code = 0; result.Msg = "成功"; } else { result.Code = 1; result.Msg = "失败"; } } catch (Exception ex) { result.Code = 1; result.Msg = ex.Message; } return(result); } }
public async Task <IActionResult> LogIn(CredentialsDto credentials) { var user = this._identityService.Authentication(credentials); var result = new StandardResult(); if (user == null) { result.StatusCode = SAE.CommonLibrary.Common.StatusCode.AccountOrPassword; } else { var claims = new List <Claim>() { new Claim("name", user.Information.Name), new Claim(ClaimTypes.Sid, user.Id), new Claim("sub", user.Id), new Claim("role", "admin") }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(identity); await this.HttpContext.SignInAsync(principal); } return(this.Json(result)); }
public StandardResult <List <OrderResult> > GetOrderResult(OrderSearch search = null) { var result = new StandardResult <List <OrderResult> >(); using (var db = base.NewDB()) { result.Body = db.Query <OrderResult>(@"SELECT order_type, ( CASE order_type WHEN 1 THEN '特' WHEN 2 THEN '平' WHEN 4 THEN '平' ELSE '其他' END ) AS ordertypename, sort, sum(total_in_money) as Money FROM t_orders WHERE customer_id = 16 AND issue = @Issue GROUP BY order_type, sort order by sort asc" , new { Issue = search.Issue }).ToList(); } return(result); }
public StandardResult <List <OrderTJ> > GetTJ(int cid, string issue, string code, int flag = 1) { var result = new StandardResult <List <OrderTJ> >(); using (var db = base.NewDB(flag)) { StringBuilder sqlCommonText = new StringBuilder(@"select a.issue,b.code,sum(b.inmoney) as money from t_orders as a INNER JOIN t_orders_tm as b on a.id=b.orderId and a.order_type=1 where a.issue = @Issue "); if (cid != 0) { sqlCommonText.Append(" and a.customer_id=@cid "); } if (!string.IsNullOrWhiteSpace(code)) { sqlCommonText.Append(" and b.code=@Code "); } sqlCommonText.Append(" group by a.issue, b.code order by money desc"); result.Body = db.Query <OrderTJ>(sqlCommonText.ToString(), new { Issue = issue, cid = cid, Code = code }).ToList(); result.Body.ForEach(x => { x.Code2 = x.Code; x.Code = x.Code + "\n" + ServiceNum.GetNumsArray().FirstOrDefault(P => P.Value == x.Code).Zodiac; }); result.Code = 0; return(result); } }
public StandardResult AddOrderLXLM(Order <OrderLXLM> model, int flag = 1) { var result = new StandardResult(); using (var db = base.NewDB(flag)) { db.Open(); IDbTransaction trans = db.BeginTransaction(); try { if (AddOrderMain(model, trans).Code != 0) { throw new Exception("订单主表添加失败"); } if (AddOrderLXLMDetails(model.OrderDetails, trans).Code != 0) { throw new Exception("订单明细添加失败"); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); result.Code = 1; result.Msg = "失败"; } } return(result); }
public ActionResult Register(UserRegisterModel model) { this._identityService.Create(model); var result = new StandardResult(); return(this.Json(result)); }
public static StandardResult <bool> Execute(SimpleTable sourceTable) { foreach (var row in sourceTable) { var message = new MailMessage(row["Mail-From"], row["Mail-To"]) { Subject = row["Mail-Subject"], Body = row["Mail-Body"] }; if (sourceTable.ContainColumn("Mail-CC")) { var cc = row["Mail-CC"]; if (!string.IsNullOrWhiteSpace(cc)) { message.CC.Add(cc); } } message.IsBodyHtml = true; var result = SendEMail.Execute(message); if (result.HasError) { return(result); } } return(StandardResult <bool> .ReturnResult(true)); }
public ICommandResult Handle(StudentInputRegister command) { var course = new Course(command.CourseId); string password = string.Empty; string salt = string.Empty; if (!string.IsNullOrEmpty(command.CPF)) { password = _encryptor.Encrypt(command.CPF.Replace("-", "").Replace(".", ""), out salt); } var student = new Student(course, command.Birthdate, command.FirstName, command.LastName, command.CPF, command.Email, command.Phone, command.Gender, command.Country, command.City, command.Address, password, salt); var result = new StandardResult(); if (_SREP.Get(student.CPF.Number) != null) { result.Notifications.Add("CPF", "CPF já foi cadastrado!"); } result.AddRange(student.Notifications); if (result.Notifications.Count == 0) { _SREP.Create(student); result.Notifications.Add("Success", "O Acadêmico foi salvo"); } return(result); }
public static StandardResult <string> Execute(SimpleTable table, bool escape = true) { var sb = new StringBuilder(); foreach (var column in table.ColumnNames) { sb.Append(column); sb.Append('\t'); } sb.Length = sb.Length - 1; sb.AppendLine(); foreach (var row in table) { for (int i = 0; i < row.ColumnCount; i++) { var value = row[i]; if (escape) { value = Escape(value); } sb.Append(value); sb.Append('\t'); } sb.Length = sb.Length - 1; sb.AppendLine(); } return(StandardResult <string> .ReturnResult(sb.ToString())); }
public void ShouldCreateStudentWithSuccess() { StandardResult result = (StandardResult)handler.Handle(commandRegister); Assert.IsTrue(result.IsValid); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Success")); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IJsonConvertor jsonConvertor, IFileDecorator fileDecorator) { app.UseStatusCodePages() .UseStaticFiles(); app.Map("/upload", builder => { builder.Run(async context => { var result = new StandardResult(); if (context.Request?.Form?.Files == null || context.Request.Form.Files.Count <= 0) { result.StatusCode = StatusCode.RequestInvalid; result.Message = "请上传文件!"; } else { List <FileDecorator> fileDecorators = new List <FileDecorator>(); foreach (var fileContext in context.Request.Form.Files.Select(f => new FileContext(f.FileName, f.OpenReadStream(), context))) { await fileDecorator.Decorate(fileContext); } result.Body = fileDecorators; } await context.Response.WriteAsync(jsonConvertor.Serialize(result)); }); }); }
public ICommandResult Handle(EnrollmentInputDeny command) { _EREP.Cancel(command.EnrollmentId); var result = new StandardResult(); result.Notifications.Add("Success", "A Matrícula foi negada."); return(result); }
public ICommandResult Handle(EnrollmentInputConfirm command) { _EREP.Confirm(command.EnrollmentId); var result = new StandardResult(); result.Notifications.Add("Success", "A Matrícula foi confirmada."); return(result); }
public ICommandResult Handle(ActivityInputDelete command) { _AREP.Delete(command.Id); var result = new StandardResult(); result.Notifications.Add("Success", "A atividade foi excluida."); return(result); }
public static StandardResult <SimpleTable> Execute(SimpleTable sourceTable, SimpleTable expandTable) { if (sourceTable == null) { return(StandardResult <SimpleTable> .ReturnError("ExpandTable() error: source table null")); } if (expandTable == null) { return(StandardResult <SimpleTable> .ReturnError("ExpandTable() error: aggregate table null")); } var newTable = sourceTable.Copy(); // create columns foreach (var map in expandTable) { var source = map["source"]; var destination = map["destination"]; newTable.AddColumnName(destination); var expression = ExpressionCache.Compile(source); if (expression == null) { return(StandardResult <SimpleTable> .ReturnError("AggregateTable() error: evaluator returns null", "Source: " + source)); } } var fieldSource = new FieldDataSource(); foreach (var newRow in newTable) { fieldSource.Row = newRow; foreach (var map in expandTable) { var source = map["source"]; var destination = map["destination"]; var expression = ExpressionCache.Compile(source); var result = expression.Evaluate(new Context() { FieldSource = fieldSource }); if (result.IsError) { return(StandardResult <SimpleTable> .ReturnError("ExpandTable() error: occurred during evaluating: " + expression.Parser.Tokenizer.Expression, result.String)); } newRow[destination] = ToString(result); } } return(StandardResult <SimpleTable> .ReturnResult(newTable)); }
public static StandardResult <SimpleTable> Execute(SimpleTable sourceTable, string sourceKeyField, string mergeField, SimpleTable lookupTable, string lookupKeyField, string lookupDataField, bool overwrite, bool caseInsensitive = true) { if (!sourceTable.ColumnNames.Contains(sourceKeyField)) { return(StandardResult <SimpleTable> .ReturnError("LookupUpdateTable() error: source key field does not exists: " + sourceKeyField)); } if (!sourceTable.ColumnNames.Contains(mergeField)) { return(StandardResult <SimpleTable> .ReturnError("LookupUpdateTable() error: merge field does not exists: " + mergeField)); } var newTable = new SimpleTable(); foreach (var column in sourceTable.ColumnNames) { newTable.AddColumnName(column); } foreach (var sourceRow in sourceTable) { var newRow = newTable.CreateRow(); for (int i = 0; i < sourceRow.ColumnCount; i++) { var value = sourceRow[i]; if (value == null) { continue; } newRow[i] = value; } } foreach (var row in newTable) { string key = row[sourceKeyField]; if (!overwrite && !string.IsNullOrWhiteSpace(row[mergeField])) { continue; } if (caseInsensitive) { key = key.ToLower(); } string lookup = Lookup(lookupTable, key, lookupKeyField, lookupDataField); row[mergeField] = lookup; } return(StandardResult <SimpleTable> .ReturnResult(newTable)); }
public static StandardResult <bool> Execute(MailMessage message) { if (!MailHelper.SendMailMessage(message, out Exception e)) { return(StandardResult <bool> .ReturnError("SendEMail() error: unable to send e-mail to: " + message.To, "Reason: " + e.ToString(), e)); } return(StandardResult <bool> .ReturnResult(true)); }
public static StandardResult <SimpleTable> Execute(string data, string newRow, char delimiter = '=', IList <string> columns = null) { var lines = data.Split(new string[] { "\r\n" }, StringSplitOptions.None); var table = new SimpleTable(); if (columns != null) { for (int i = 0; i < columns.Count; i++) { table.SetColumnName(i, columns[i]); } } SimpleTableRow row = null; foreach (var line in lines) { if (string.IsNullOrEmpty(line)) { continue; } if (line.StartsWith("#")) { continue; } if (line == newRow) { row = table.CreateRow(); continue; } int pos = line.IndexOf(delimiter); if (pos < 0) { continue; } string name = line.Substring(0, pos); string value = line.Substring(pos + 1); if (columns == null && !table.ContainColumn(name)) { table.SetColumnName(table.ColumnNames.Count, name); } if (table.ContainColumn(name)) { row.SetField(name, value); } } return(StandardResult <SimpleTable> .ReturnResult(table)); }
public static StandardResult <SimpleTable> Execute(string data, bool containsHeader = true, bool mapHeaderNames = true, bool unespace = true) { var lines = data.Split(new string[] { "\r\n" }, StringSplitOptions.None); var start = 0; var table = new SimpleTable(); if (containsHeader) { start = 1; if (mapHeaderNames) { var parts = lines[0].Split('\t'); for (int i = 0; i < parts.Length; i++) { var value = parts[i]; if (string.IsNullOrWhiteSpace(value)) { continue; } table.SetColumnName(i, value); } } } for (int index = start; index < lines.Length; index++) { var line = lines[index]; if (index + 1 == lines.Length && string.IsNullOrWhiteSpace(line)) { continue; } var parts = line.Split('\t'); var row = table.CreateRow(); for (int i = 0; i < parts.Length; i++) { var part = parts[i]; if (unespace) { part = Unescape(part); } row.SetField(i, part); } } return(StandardResult <SimpleTable> .ReturnResult(table)); }
public StandardResult <Customers> GetModel(Customers model) { StandardResult <Customers> result = new StandardResult <Customers>(); using (var db = base.NewDB()) { string sqlCommandText = "select * from t_customers where id=@Id"; result.Body = db.Query <Customers>(sqlCommandText, model).FirstOrDefault(); return(result); } }
public void ShouldDeleteStudentWithSuccess() { commandDelete = new StudentInputDelete() { StudentId = student.Id }; StandardResult result = (StandardResult)handler.Handle(commandDelete); var studentDB = _SREP.Get(student.Id); Assert.AreEqual(studentDB, null); }
public StandardResult <List <Customers> > GetList(Customers model) { StandardResult <List <Customers> > result = new StandardResult <List <Customers> >(); using (var db = base.NewDB()) { string sqlCommandText = "select * from t_customers where isdel=@IsDel"; result.Body = db.Query <Customers>(sqlCommandText, model).AsList(); return(result); } }
public void ShouldDeleteProfessorWithSuccess() { commandDelete = new ProfessorInputDelete() { ProfessorId = professor.Id }; StandardResult result = (StandardResult)handler.Handle(commandDelete); var professorDB = _PREP.Get(professor.Id); Assert.IsFalse(professorDB.Active); }
public StandardResult <List <OrderLXLM> > GetOrderLXLMList(string orderId) { Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true; var result = new StandardResult <List <OrderLXLM> >(); using (var db = base.NewDB()) { StringBuilder sqlCommonText = new StringBuilder("select * from t_orders_lxlm where orderid=@OrderId"); result.Body = db.Query <OrderLXLM>(sqlCommonText.ToString(), new { OrderId = orderId }).ToList(); return(result); } }
public IHttpActionResult Help(int id, string accessToken, int channel, int platform, string ver) { Logger.WriterLogger("Common.Help, Params: " + string.Format("accessToken={0}&channel={1}&platform={2}&ver={3}&id={4}", accessToken, channel, platform, ver, id), LoggerType.Info); // 保存访问信息 base.SaveVisitInfo("", channel, platform, ver); // 验证令牌 int accessTookenCode = VerifyAccessToken(accessToken); if (accessTookenCode > 0) { return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), "Common.Help")); } HelpListItem item = new HelpListItem(); HelpInfo help = CommentBrowser.GetHelp(id); if (help != null) { item.CategoryId = help.CategoryId; item.Id = help.HelpId; item.Title = help.Title; item.Description = help.Description; var regex = new Regex(@"""/Storage/master"); item.Content = regex.Replace(help.Content, "\"" + base.STORAGE_HOST + @"/Storage/master"); item.Content = StringExtension.CovertToHtml(item.Content); item.AddedDate = help.AddedDate.ToString("yyyy-MM-dd HH:mm:ss"); return(base.JsonActionResult(new StandardResult <HelpListItem>() { code = 0, msg = "", data = item })); } else { StandardResult <string> result = new StandardResult <string>() { code = 1, msg = "找不到该帮助内容", data = "" }; return(base.JsonActionResult(result)); } }
public StandardResult <List <OddsData> > GetList(int cid) { Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true; var result = new StandardResult <List <OddsData> >(); using (var db = base.NewDB()) { var list = db.Query <OddsData>("select * from t_odds where customerId=@CustomerId", new { CustomerId = cid }); result.Body = list.ToList(); return(result); } }
protected JsonResult JResult(StandardResult ret) { return Json(new { ret = ret.Ret, msg = ret.Msg, id = ret.Num }, "text/html", Encoding.UTF8, JsonRequestBehavior.DenyGet); }