本文整理汇总了C#中ServiceResult类的典型用法代码示例。如果您正苦于以下问题:C# ServiceResult类的具体用法?C# ServiceResult怎么用?C# ServiceResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceResult类属于命名空间,在下文中一共展示了ServiceResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: ServiceResponse
/// <summary>
/// Initializes a new instance of the <see cref="ServiceResponse"/> class.
/// This is intended to be used by unit tests to create a fake service error response
/// </summary>
/// <param name="responseCode">Response code</param>
/// <param name="errorMessage">Detailed error message</param>
internal ServiceResponse(ServiceError responseCode, string errorMessage)
{
this.result = ServiceResult.Error;
this.errorCode = responseCode;
this.errorMessage = errorMessage;
this.errorDetails = null;
}
示例3: 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;
}
示例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: AddPropertyTag
public ServiceResult<IPropertyTag> AddPropertyTag(string pin, string name)
{
ServiceResult<IPropertyTag> retVal = new ServiceResult<IPropertyTag>();
FVCP.Persistence.EF.PropertyTag dbItem = null;
using (var db = new PropertyEntities())
{
dbItem = db.PropertyTags
.FirstOrDefault(x => x.Pin == pin && x.Name == name);
if (dbItem == null)
{ // Go ahead and add the item, it isn't a duplicate.
dbItem = new EF.PropertyTag()
{
Name = name,
Pin = pin
};
db.PropertyTags.Add(dbItem);
db.SaveChanges(); // ID value should populate.
PropertyTagDTO dto = PropertyTagRepository.MapFieldValues(dbItem);
PropertyTagFactory myFact = new PropertyTagFactory();
retVal.Data = myFact.Create(dto);
retVal.Success = true;
}
else
{
retVal.Success = false;
retVal.ErrorID = "422";
retVal.Message = string.Format("Unprocessable Entity - Tag '{0}' already exists for PIN '{1}'", name, pin);
}
}
return retVal;
}
示例6: 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;
}
示例7: UpdatePropertyTag
public ServiceResult<IPropertyTag> UpdatePropertyTag(int id, string name)
{
ServiceResult<IPropertyTag> retVal = new ServiceResult<IPropertyTag>();
FVCP.Persistence.EF.PropertyTag dbItem = null;
using (var db = new PropertyEntities())
{
dbItem = db.PropertyTags
.FirstOrDefault(x => x.Id == id);
if (dbItem != null)
{
dbItem.Name = name;
db.SaveChanges();
PropertyTagFactory myFact = new PropertyTagFactory();
retVal.Data = myFact.Create(GetPropertyTagById(id).Data);
retVal.Success = true;
}
else
{ // Item doesn't exist.
retVal.Success = false;
retVal.ErrorID = "404";
retVal.Message = string.Format("Tag id '{0}' was not found. Unable to update property tag '{1}'.",
id, name);
}
}
return retVal;
}
示例8: AlbumCallback
public void AlbumCallback(ServiceResult<Album> serviceResult)
{
// Adding Dir to control;
this.Invoke((HyvesServicesCallback<Album>)delegate(ServiceResult<Album> result) { AddAlbumInListView(result.Result); }, serviceResult);
List<string> files = new List<string>();
foreach (FileInfo file in this.uploadDirectory.GetFiles())
{
files.Add(file.FullName);
}
if (files.Count == 0)
{
return;
}
// uploading files
this.Invoke((HyvesServicesCallback<Album>)delegate(ServiceResult<Album> result)
{
lvMedia.Tag = result.Result;
HyvesBatchUploadRequest hyvesBatchUploadRequest = MediaService.UploadFiles(files, result.Result, new HyvesServicesCallback<HyvesBatchUploadRequest>(HyvesBatchUploadCallback));
hyvesBatchUploadRequest.OnBatchUploadProgressChanged += new HyvesServicesCallback<int>(hyvesBatchUploadRequest_OnBatchUploadProgressChanged);
uploadProgress.Completed = 0;
uploadProgress.Total = files.Count;
uploadProgress.ShowDialog();
}, serviceResult);
}
示例9: 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;
}
示例10: AddVendor
public ServiceResult<Vendor> AddVendor(string name, int? defaultCategoryId = null)
{
var result = new ServiceResult<Vendor>();
// TODO do we need to handle a case where defaultCategoryId = 0
//if (defaultCategoryId.HasValue && defaultCategoryId.Value == 0)
// defaultCategoryId = null;
// does category exist?
if (defaultCategoryId.HasValue)
{
var categoryResult = _categoryService.GetCategory(defaultCategoryId.Value);
if (categoryResult.HasErrors)
{
result.AddErrors(categoryResult);
return result;
}
}
// create Vendor
var vendor = new Vendor()
{
Name = name,
DefaultCategoryId = defaultCategoryId
};
_db.Insert<Vendor>(vendor);
result.Result = vendor;
return result;
}
示例11: AddCategory
public ServiceResult<Category> AddCategory(string name, int? categoryGroupId = null)
{
var result = new ServiceResult<Category>();
// does Category Group exist?
if (categoryGroupId.HasValue)
{
var categoryGroupResult = GetCategoryGroup(categoryGroupId.Value);
if (categoryGroupResult.HasErrors)
{
result.AddErrors(categoryGroupResult);
return result;
}
}
// create Category
var category = new Category()
{
Name = name,
CategoryGroupId = categoryGroupId,
};
_db.Insert<Category>(category);
result.Result = category;
return result;
}
示例12: Create
public ActionResult Create(DetailsViewModel model)
{
var groups = GetForeignData();
ViewBag.Data_GroupID = groups;
ServiceResult result = new ServiceResult();
TempData["Service_Result"] = result;
if (ModelState.IsValid)
{
try
{
MemberService.Create(model);
result.Message = "添加会员信息成功!";
LogHelper.WriteLog("添加会员信息成功");
return RedirectToAction("index");
}
catch (Exception ex)
{
result.Message = Utilities.GetInnerMostException(ex);
result.AddServiceError(result.Message);
LogHelper.WriteLog("添加会员信息错误", ex);
return View(model);
}
}
else
{
result.Message = "请检查表单是否填写完整!";
result.AddServiceError("请检查表单是否填写完整!");
return View(model);
}
}
示例13: AccessTokenCallback
private void AccessTokenCallback(ServiceResult<AccessToken> serviceResult)
{
HyvesApplication hyvesApplication = HyvesApplication.GetInstance();
hyvesApplication.AccessToken = serviceResult.Result.oauth_token;
hyvesApplication.AccessTokenSecret = serviceResult.Result.oauth_token_secret;
hyvesApplication.UserId = serviceResult.Result.userid;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
示例14: RequestTokenCallback
private void RequestTokenCallback(ServiceResult<RequestToken> serviceResult)
{
StartLoginDelegate startLoginDelegate = new StartLoginDelegate(StartLogin);
HyvesApplication hyvesApplication = HyvesApplication.GetInstance();
hyvesApplication.RequestToken = serviceResult.Result.oauth_token;
hyvesApplication.RequestTokenSecret = serviceResult.Result.oauth_token_secret;
// Showing LoginForm to user
this.BeginInvoke(startLoginDelegate, serviceResult.Result.oauth_token);
}
示例15: AccessTokenResponseCallback
private static void AccessTokenResponseCallback(RequestResult<AccessToken> requestResult)
{
ServiceResult<AccessToken> serviceResult = new ServiceResult<AccessToken>() { IsError = requestResult.IsError, Execption = requestResult.Execption, Message = requestResult.Message };
if (!requestResult.IsError)
{
AccessToken requestToken = JsonConvert.DeserializeObject<AccessToken>(requestResult.Response);
serviceResult.Result = requestToken;
}
requestResult.Callback(serviceResult);
}