本文整理汇总了C#中ServiceResult.AddError方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceResult.AddError方法的具体用法?C# ServiceResult.AddError怎么用?C# ServiceResult.AddError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceResult
的用法示例。
在下文中一共展示了ServiceResult.AddError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProjectVersion
public async Task<IServiceResult> CreateProjectVersion(ProjectVersionEditViewModel model)
{
var result = new ServiceResult<ProjectVersionEditViewModel>();
try
{
var project = await ProjectStore.GetAll().Include(p => p.Versions).SingleOrDefaultAsync(p => p.Id == model.ProjectId);
if (project == null)
{
result.AddError(m => m.ProjectId, "Ilyen azonosítóval nem létezik projekt!");
return result;
}
var version = Mapper.Map<ProjectVersionEditViewModel, ProjectVersion>(model);
version.Project = project;
await ProjectVersionStore.InsertAsync(version);
}
catch (Exception e)
{
Log.Error(e.Message, e);
result.AddError("", e.Message);
}
return result;
}
示例2: CreateSpentTime
public async Task<IServiceResult> CreateSpentTime(SpentTimeEditViewModel model)
{
var result = new ServiceResult<SpentTimeEditViewModel>();
try
{
var user = await userManager.FindByIdAsync(model.UserId);
if(user == null)
{
result.AddError("", "Ez a felhasználó nem létezik");
}
var issue = await context.Issues.FindAsync(model.IssueId);
if(issue == null)
{
result.AddError(m => m.IssueId, "Ez a feladat nem létezik");
}
if(result.Succeeded)
{
var spentTime = mapper.Map<SpentTime>(model);
spentTime.User = user;
spentTime.Issue = issue;
context.SpentTimes.Add(spentTime);
await context.SaveChangesAsync();
}
}
catch (Exception e)
{
result.AddError("", e.Message);
}
return result;
}
示例3: CreateIssue
public async Task<IServiceResult> CreateIssue(IssueEditViewModel model)
{
var result = new ServiceResult<IssueEditViewModel>();
try
{
var project = await context.Projects.FindAsync(model.ProjectId);
if(project == null)
{
result.AddError(m => m.ProjectId, "Ilyen projekt nem létezik");
return result;
}
var issue = mapper.Map<Issue>(model);
issue.Project = project;
issue.State = IssueState.New;
context.Issues.Add(issue);
await context.SaveChangesAsync();
}
catch (Exception e)
{
result.AddError("", e.Message);
}
return result;
}
示例4: CreateProject
public async Task<IServiceResult> CreateProject(ProjectEditViewModel model)
{
var result = new ServiceResult<ProjectEditViewModel>();
try
{
var responsible = await userManager.FindByIdAsync(model.ResponsibleUserId);
if(responsible == null)
{
result.AddError(m => m.ResponsibleUserId, "Ilyen felhasználó nem létezik");
}
if(result.Succeeded)
{
var project = mapper.Map<Project>(model);
project.Responsible = responsible;
context.Projects.Add(project);
await context.SaveChangesAsync();
}
}
catch (Exception e)
{
result.AddError("", e.Message);
}
return result;
}
示例5: ChangeState
public async Task<ServiceResult> ChangeState(int issueId, IssueState newState)
{
var result = new ServiceResult();
try
{
//franc se tudja miért, de ha nincs ráincludeolva a project, elszáll a required miatt...
var issue = await context.Issues.Include(i => i.Project).SingleOrDefaultAsync(i => i.Id == issueId);
if (issue == null)
{
result.AddError("", "Nincs ilyen azonosítójú feladat.");
return result;
}
issue.State = newState;
await context.SaveChangesAsync();
}
catch (Exception e)
{
result.AddError("", e.Message);
}
return result;
}
示例6: GetVendor
public ServiceResult<Vendor> GetVendor(string name)
{
var result = new ServiceResult<Vendor>();
var vendor = _db.Connection.Query<Vendor>("SELECT * FROM Vendor WHERE Name = @name", new { name });
if (vendor == null || !vendor.Any())
{
result.AddError(ErrorType.NotFound, "Vendor {0} not found", name);
return result;
}
// are there multiple vendors with the same name?
if (vendor.Count() > 1)
{
result.AddError(ErrorType.Generic, "Multiple Vendors with name {0} exist", name);
return result;
}
result.Result = vendor.First();
return result;
}
示例7: GetCategory
public ServiceResult<Category> GetCategory(string name)
{
var result = new ServiceResult<Category>();
var category = _db.Connection.Query<Category>("SELECT * FROM Category WHERE Name = @name", new { name });
if (category == null || !category.Any())
{
result.AddError(ErrorType.NotFound, "Category {0} not found", name);
return result;
}
// are there multiple categories with the same name?
if (category.Count() > 1)
{
result.AddError(ErrorType.Generic, "Multiple Categories with name {0} exist", name);
return result;
}
result.Result = category.First();
return result;
}
示例8: CreateComment
public async Task<IServiceResult> CreateComment(CommentEditViewModel model)
{
var result = new ServiceResult<CommentEditViewModel>();
try
{
var issue = await context.Issues.FindAsync(model.IssueId);
if (issue == null)
{
result.AddError(m => m.IssueId, "Ez a feladat nem létezik");
}
var user = await userManager.FindByIdAsync(model.UserId);
if (user == null)
{
result.AddError(m => m.UserId, "Ez a felhasználó nem létezik");
}
if (result.Succeeded)
{
var comment = mapper.Map<Comment>(model);
comment.User = user;
comment.Issue = issue;
comment.Created = DateTime.Now;
context.Comments.Add(comment);
await context.SaveChangesAsync();
result.Data = mapper.Map<Comment, CommentListViewModel>(comment);
}
}
catch (Exception e)
{
result.AddError("", e.Message);
}
return result;
}
示例9: CreatePlatform
/// <summary>
/// Készít egy új platformot
/// </summary>
/// <param name="model">Az új platform modelje</param>
/// <returns></returns>
public async Task<IServiceResult> CreatePlatform(PlatformEditViewModel model)
{
var result = new ServiceResult<PlatformEditViewModel>();
try
{
await TestPlatformStore.InsertAsync(Mapper.Map<PlatformEditViewModel, Platform>(model));
}
catch (Exception e)
{
Log.Error(e.Message, e);
result.AddError("", e.Message);
}
return result;
}
示例10: DeleteBudgetCategory
public ServiceResult<bool> DeleteBudgetCategory(int categoryId, DateTime month)
{
// TODO handle cascading deletes
var result = new ServiceResult<bool>();
bool deletionResult = false;
// does category exist?
var categoryResult = _categoryService.GetCategory(categoryId);
if (categoryResult.HasErrors)
{
result.AddErrors(categoryResult);
return result;
}
// does budget category exist?
var predicates = new List<IPredicate>();
predicates.Add(Predicates.Field<BudgetCategory>(x => x.Month, Operator.Eq, month));
predicates.Add(Predicates.Field<BudgetCategory>(x => x.CategoryId, Operator.Eq, categoryId));
var predicate = new PredicateGroup { Operator = GroupOperator.And, Predicates = predicates };
var budgetCategory = _db.GetList<BudgetCategory>(predicate);
// are there multiple budget categories with the same month?
if (budgetCategory.Count() > 1)
{
result.AddError(ErrorType.Generic, "Multiple Budget Categories for month {0} exist", month.ToShortDateString());
return result;
}
// is this an existing budget category?
else if (budgetCategory.Count() == 1)
{
var existingBudgetCategory = budgetCategory.First();
deletionResult = _db.Delete<BudgetCategory>(existingBudgetCategory);
}
result.Result = deletionResult;
return result;
}
示例11: GetTransaction
public ServiceResult<Transaction> GetTransaction(int transactionId)
{
var result = new ServiceResult<Transaction>();
var transactionsResult = GetTransactions(new Filter<int>(transactionId));
if (transactionsResult.HasErrors)
{
result.AddErrors(transactionsResult);
return result;
}
if (transactionsResult.Result.Count() > 1)
{
result.AddError(ErrorType.Generic, "More than one transaction with Id {0} found", transactionId);
return result;
}
result.Result = transactionsResult.Result.First();
return result;
}
示例12: DeleteAccountGroup
public ServiceResult<bool> DeleteAccountGroup(int accountGroupId)
{
// TODO handle cascading deletes
var result = new ServiceResult<bool>();
var deletionResult = _db.Delete<AccountGroup>(Predicates.Field<AccountGroup>(x => x.Id, Operator.Eq, accountGroupId));
if (!deletionResult)
{
result.AddError(ErrorType.NotFound, "AccountGroup {0} not found", accountGroupId);
return result;
}
result.Result = deletionResult;
return result;
}
示例13: UpdateBill
public ServiceResult<Bill> UpdateBill(int billId, string name, decimal amount, int billGroupId, int? categoryId, int? vendorId, DateTime startDate, DateTime endDate, int frequency, bool updateExisting, DateTime? secondaryStartDate, DateTime? secondaryEndDate)
{
ServiceResult<Bill> result = new ServiceResult<Bill>();
var bill = _billRepository.GetById(billId);
if (bill == null)
{
result.AddError(ErrorType.NotFound, "Bill {0} not found", billId);
return result;
}
// TODO do we need to do exist checks for billGroupId, categoryId, vendorId?
if (categoryId.HasValue && categoryId.Value == 0)
categoryId = null;
if (vendorId.HasValue && vendorId.Value == 0)
vendorId = null;
if (updateExisting)
{
if (bill.StartDate != startDate || bill.EndDate != endDate || bill.RecurrenceFrequency != frequency || bill.StartDate2 != secondaryStartDate || bill.EndDate2 != secondaryEndDate)
{
List<BillTransaction> existing = _billTransactionRepository.GetMany(x => x.BillId == billId).ToList();
List<BillTransaction> expected = new List<BillTransaction>();
#region Generate expected transactions
int count = 0;
DateTime cur = new DateTime(startDate.Year, startDate.Month, startDate.Day);
while (cur <= endDate)
{
BillTransaction trx = new BillTransaction()
{
Amount = amount,
OriginalAmount = amount,
CategoryId = categoryId,
OriginalCategoryId = categoryId,
VendorId = vendorId,
OriginalVendorId = vendorId,
Timestamp = cur,
OriginalTimestamp = cur
};
expected.Add(trx);
count++;
if (frequency == 0)
cur = endDate.AddDays(1);
else if (frequency > 0)
cur = startDate.AddDays(count * frequency);
else
cur = startDate.AddMonths(count * -1 * frequency);
}
if (secondaryStartDate.HasValue)
{
if (secondaryEndDate.HasValue)
endDate = secondaryEndDate.Value;
count = 0;
cur = new DateTime(secondaryStartDate.Value.Year, secondaryStartDate.Value.Month, secondaryStartDate.Value.Day);
while (cur <= endDate)
{
BillTransaction trx = new BillTransaction()
{
Amount = amount,
OriginalAmount = amount,
CategoryId = categoryId,
OriginalCategoryId = categoryId,
VendorId = vendorId,
OriginalVendorId = vendorId,
Timestamp = cur,
OriginalTimestamp = cur
};
expected.Add(trx);
count++;
if (frequency == 0)
cur = endDate.AddDays(1);
else if (frequency > 0)
cur = secondaryStartDate.Value.AddDays(count * frequency);
else
cur = secondaryStartDate.Value.AddMonths(count * -1 * frequency);
}
}
#endregion
List<BillTransaction> reused = new List<BillTransaction>();
while (existing.Any() && expected.Any())
{
var existingProjections = existing.Select(e => new
{
Item = e,
Comparisons = expected.Select(x => new
{
Item = x,
//.........这里部分代码省略.........
示例14: RenameVendor
public ServiceResult<Vendor> RenameVendor(int vendorId, string name)
{
ServiceResult<Vendor> result = new ServiceResult<Vendor>();
// does this vendor even exist?
var vendor = _vendorRepository.GetById(vendorId);
if (vendor == null)
{
result.AddError(ErrorType.NotFound, "Vendor with Id {0} not found", vendorId);
return result;
}
// see if a vendor with this name already exists
var existingVendor = _vendorRepository.Get(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
if (existingVendor != null && existingVendor != vendor)
{
foreach (var trx in vendor.Transactions)
{
trx.VendorId = existingVendor.Id;
}
foreach (var bill in vendor.Bills)
{
foreach (var billTrx in bill.BillTransactions)
{
if (billTrx.OriginalVendorId == vendorId)
{
billTrx.OriginalVendorId = existingVendor.Id;
}
if (billTrx.VendorId == vendorId)
{
billTrx.VendorId = existingVendor.Id;
}
}
bill.VendorId = existingVendor.Id;
}
_vendorRepository.Delete(vendor);
// keep track of the rename in the mappings table
existingVendor.ImportDescriptionVendorMaps.Add(new ImportDescriptionVendorMap() { Description = vendor.Name });
result.Result = existingVendor;
}
else
{
// if there's not an existing vendor with this name, just rename the one we have
// keep track of the rename in the mappings table
vendor.ImportDescriptionVendorMaps.Add(new ImportDescriptionVendorMap() { Description = vendor.Name });
vendor.Name = name;
result.Result = vendor;
}
_unitOfWork.Commit();
return result;
}
示例15: PredictBillTransactionMatch
public ServiceResult<List<Tuple<Transaction, double>>> PredictBillTransactionMatch(int billTransactionId)
{
var result = new ServiceResult<List<Tuple<Transaction, double>>>();
var billTransaction = _billTransactionRepository.GetById(billTransactionId);
if (billTransaction == null)
{
result.AddError(ErrorType.NotFound, "Bill transaction {0} not found", billTransactionId);
return result;
}
// find predictions if it's not paid, or there are no associated transactions to indicate the paid status
if (!billTransaction.IsPaid || !billTransaction.Transactions.Any())
{
var timestampLower = billTransaction.Timestamp.AddMonths(-2);
var timestampUpper = billTransaction.Timestamp.AddMonths(2);
var amountLower = billTransaction.Amount / 5.0M;
var amountUpper = billTransaction.Amount * 5.0M;
var amount = amountUpper;
amountUpper = Math.Max(amountLower, amountUpper);
amountLower = Math.Min(amount, amountLower);
// find reasonable predictions
var predictions = _transactionRepository.GetMany(x =>
(x.Amount > amountLower && x.Amount < amountUpper)
&& (x.Timestamp > timestampLower && x.Timestamp < timestampUpper)).ToList();
// calculate confidence level
var billTransactionVendorName = billTransaction.Vendor == null ? "" : billTransaction.Vendor.Name;
var confidences = predictions.Select(x => new Tuple<Transaction, double>(x,
(.1 * Math.Exp(-1 * Math.Pow((double)((x.Amount - billTransaction.Amount) / billTransaction.Amount), 2.0) / 2.0)
+ .2 * Math.Exp(-1 * Math.Pow(((x.Timestamp - billTransaction.Timestamp).TotalDays / 60.0), 2.0))
+ .2 * (x.Timestamp.Month == billTransaction.Timestamp.Month ? 1 : 0)
+ .2 * ((x.VendorId.HasValue && (x.VendorId == billTransaction.VendorId)) ? 1 : 0)
+ .3 * Math.Exp(-1 * Math.Pow(LevenshteinDistance.Compute(x.Vendor == null ? "" : x.Vendor.Name, billTransactionVendorName) / 20.0, 2.0)))
* (x.BillTransaction == null ? 1.0 : 0.0)
));
// debug
//Debug.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", "", billTransaction.Amount, billTransaction.Timestamp, billTransaction.VendorId, billTransactionVendorName, LevenshteinDistance.Compute(billTransactionVendorName, billTransactionVendorName));
//predictions.ForEach(p =>
//{
// var vendorName = p.Vendor == null ? "" : p.Vendor.Name;
// Debug.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", p.Id, p.Amount, p.Timestamp, p.VendorId, vendorName, LevenshteinDistance.Compute(vendorName, billTransactionVendorName));
//});
// order by confidence
result.Result = confidences
.OrderByDescending(x => x.Item2)
.Take(5)
.ToList();
}
return result;
}