public List <ErrorFields> ValidateObject(object t) { List <ErrorFields> rl = new List <ErrorFields>(); try { ValidationContext context = new ValidationContext(t, null, null); List <ValidationResult> results = new List <ValidationResult>(); bool valid = Validator.TryValidateObject(t, context, results, true); if (!valid) { foreach (ValidationResult vr in results) { ErrorFields r = new ErrorFields(); // r.field = vr.MemberNames.First(); r.message = vr.ErrorMessage; rl.Add(r); } } } catch (Exception ex) { ErrorFields r = new ErrorFields(); r.message = ex.Message; rl.Add(r); } return(rl); }
/// <summary> /// Get the string presentation of the object /// </summary> /// <returns>String presentation of the object</returns> public override string ToString() { var sb = new StringBuilder(); sb.Append("class PaymentFailureNotificationContent {\n"); sb.Append(" ErrorFields: ").Append(ErrorFields.ObjectListToString()).Append("\n"); sb.Append(" ErrorMessage: ").Append(ErrorMessage).Append("\n"); sb.Append(" ModificationMerchantReference: ").Append(ModificationMerchantReference).Append("\n"); sb.Append(" ModificationPspReference: ").Append(ModificationPspReference).Append("\n"); sb.Append(" PaymentMerchantReference: ").Append(PaymentMerchantReference).Append("\n"); sb.Append(" PaymentPspReference: ").Append(PaymentPspReference).Append("\n"); sb.Append("}\n"); return(sb.ToString()); }
public bool Validate(ModelStateDictionary modelState) { var result = true; foreach (var field in modelState) { if (field.Value.Errors.Count > 0) { Messages.AddRange(field.Value.Errors.Select(e => e.ErrorMessage)); ErrorFields.Add(field.Key); result = false; } } return(result); }
public override object GetField(Fwk.Main.Common.Enums.Fields.Fields field) { ErrorFields xrField = (ErrorFields)field; if (xrField == ErrorFields.Exception) { return(Exception); } else if (xrField == ErrorFields.ErrorMessage) { return(Exception != null ? Exception.Message : "unknown error message"); } else { return(ErrorFields.NULL); } }
public override string ToString() { return($"{nameof(Success)}: {Success}, {nameof(ErrorType)}: {ErrorType}, " + $"{nameof(ErrorFields)}: {ErrorFields.ToFormattedString()}, " + $"{nameof(SystemError)}: {SystemError}"); }
public bool Valid(string fieldName) { return(String.IsNullOrEmpty(ErrorFields.FirstOrDefault(f => f == fieldName))); }
public bool Save(ModelStateDictionary modelState, int userID, int employeeID) { if (!Validate(modelState)) { return(Result = false); } QueryOutput existResult; var exist = Query <bool>(new DbQuery(userID, employeeID, DbAction.Client.View, String.Format("select count(ID) from Client where Code = '{0}' {1}", Code, ID > 0 ? String.Format("and ID <> {0}", ID) : "")), out existResult).FirstOrDefault(); if (exist) { ErrorFields.Add("Code"); Messages = new List <string>() { "Mã khách hàng đã được sử dụng" }; return(Result = false); } QueryOutput queryResult; var query = ""; var id = ID.ToString(); var action = ""; if (ID > 0) { query += String.Format(@"update Client set Name= N'{0}', Phone= N'{1}', Address = N'{2}', Point = {8}, Email = N'{3}', City = N'{4}', District = N'{5}', Code = N'{6}' where ID = {7}", new object[] { Name, Phone, Address, Email, City, District, Code, ID, Point }); action = DbAction.Client.Modify; } else { query += String.Format(@"declare @ID table(ID int) insert Client(Name, Phone, Address, Email, City, District, BussinessID, Code, Point, Status) output inserted.ID into @ID values (N'{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', {6}, N'{7}', {8}, 'active')", new object[] { Name, Phone, Address, Email, City, District, BussinessID, Code, Point }); id = "(select top 1 ID from @ID)"; action = DbAction.Client.Create; } query += String.Format(" delete ClientType where ClientID = {0}", id); if (TypeID.HasValue && TypeID > 0) { query += String.Format(" insert into ClientType(ClientID, TypeID, CreateDate, Status) values({0}, {1}, '{2}', 'active')", id, TypeID, DateTime.Now.ToString(Constants.DatabaseDatetimeString)); } Result = Execute(new DbQuery(userID, employeeID, action, query, true, id, "Name"), out queryResult); if (Result) { Messages = new List <string>() { "Lưu thông tin thành công" } } ; return(Result); }
public bool Save(ModelStateDictionary modelState, int userID, int employeeID, List <int> warehouseIDs) { QueryOutput queryResult; if (!Validate(modelState)) { return(Result = false); } if (ID == 0 && Query <bool>(new DbQuery(userID, employeeID, DbAction.Login.View, String.Format("select case when (select top 1 ID from Login where BussinessID = {0} and Username = N'{1}' and Status = 'active') is null then 0 else 1 end", BussinessID, Username)), out queryResult).FirstOrDefault()) { Messages.Add("Tài khoản đã được sử dụng"); ErrorFields.Add("Username"); return(Result = false); } if (Username != "admin" && Permission == null) { Messages.Add("Tài khoản chưa được cấp quyền"); return(Result = false); } var query = ""; var id = ID.ToString(); var action = ""; if (ID > 0) { query = String.Format(@"update Login set Username = (case when Username = '******' then 'admin' else N'{0}' end), Password = N'{1}', EmployeeID = {2}, Type = N'{4}' where ID = {3}", new object[] { Username, Password, EmployeeID.DbValue(), ID, Type }); action = DbAction.Login.Modify; } else { query = String.Format(@"declare @ID table (ID int) insert Login(Username, Password, BussinessID, EmployeeID, Status, Type) output inserted.ID into @ID values ('{0}', N'{1}', {2}, {3}, 'active', N'{4}')", new object[] { Username, Password, BussinessID, EmployeeID.DbValue(), Type }); id = "(select top 1 ID from @ID)"; action = DbAction.Login.Create; } if (Username != "admin") { query += String.Format( " if ((select count(Username) from Login where ID = {0} and Username = '******') = 0) begin delete LoginPermission where LoginID = {0}", id); var permissions = Permission.AuthorizedPermissions(); if (permissions.Count > 0) { query += String.Format(" insert into LoginPermission(LoginID, Action) values {0}", String.Join(",", permissions.Select(p => String.Format("({0}, N'{1}')", id, p)))); } if (warehouseIDs != null && warehouseIDs.Count > 0) { query += String.Format(" insert into LoginWarehouse(LoginID, WarehouseID) values {0}", String.Join(",", warehouseIDs.Select(wh => String.Format("({0}, {1})", id, wh)))); } query += " end"; } Result = Execute(new DbQuery(userID, employeeID, action, query, true, id, "Username"), out queryResult); if (Result) { Messages = new List <string>() { "Lưu thông tin thành công" } } ; return(Result); }