public async Task <IResultServiceModel <bool> > UserIsOnlyCustomer(User user) { IResultServiceModel <bool> rm = new ResultServiceModel <bool>(); try { var roleCustomer = await this.roleManager.FindByNameAsync(RoleDefinitions.Customer); if (roleCustomer != null) { if (user.Roles.Where(w => w.RoleId != roleCustomer.Id).Any()) { rm.OnSuccess(false); } else { rm.OnSuccess(true); } } else { rm.OnError(); } } catch (Exception ex) { rm.OnException(ex); } return(rm); }
public IResultServiceModel <File> FindGSByIdAndProject(long id, long projectId) { IResultServiceModel <File> rsm = new ResultServiceModel <File>(); try { var item = this.context .Files .Where(w => w.Id == id && w.Customer.ProjectId == projectId) .FirstOrDefault(); if (item != null) { rsm.OnSuccess(item); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.ITEM_DOES_NOT_EXIST); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public async Task <HttpResponseMessage> PostItem([FromBody] ProjectItemRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("ProjectPostApi", new { id = request.id }); string userId = request.userName; IResultServiceModel <ProjectItemResponse> response = new ResultServiceModel <ProjectItemResponse>(); if (!ModelState.IsValid) { response.OnError(this.GetErrorsFromModelState(), EnumErrorCode.VALIDATION_ERROR); } else { try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { IResultServiceModel <Project> rmsItem; if (request.id == 0) { rmsItem = await this.projectService.AddProjectByUserAsync(request); } else { rmsItem = await this.projectService.EditProjectByUserAsync(request); } if (rmsItem.Success) { response.OnSuccess(new ProjectItemResponse() { item = new ProjectPOCO(rmsItem.Value) }); } else { response.OnError( ErrorResources.ModelStateErrors_Format.sf(rmsItem.ErrorMessage), rmsItem.ErrorCode ); } } else { response.OnError(rmCred.ErrorMessage, rmCred.ErrorCode); } } catch (Exception ex) { response.OnException(ex); } } httpResponse = Request.CreateResponse <IResultServiceModel <ProjectItemResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public IResultServiceModel <Customer> FindByIdAndProject(long customerId, long projectId) { IResultServiceModel <Customer> rsm = new ResultServiceModel <Customer>(); try { var cuz = this.context .Customers .Where(w => w.Id == customerId && w.ProjectId == projectId) .SingleOrDefault(); if (cuz != null) { rsm.OnSuccess(cuz); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.ITEM_DOES_NOT_EXIST); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <Project> FindByIdAndUser(long projectId, User user) { IResultServiceModel <Project> rm = new ResultServiceModel <Project>(); try { var isAuthorized = this.context .UserProjects .Where(w => w.UserId == user.Id && w.ProjectId == projectId) .Any(); if (isAuthorized) { var prj = this.context.Projects.Find(projectId); rm.OnSuccess(prj); } else { rm.OnError(ProjectResources.UserHasNotEnoughPrivilegesOnThisProjectForThisAction, EnumErrorCode.INSUFFICIENT_PRIVILEGES); } } catch (Exception ex) { rm.OnException(ex); } return(rm); }
public async Task <HttpResponseMessage> History([FromUri] FileHistoryRequest request) { IResultServiceModel <FileHistoryResponse> response = new ResultServiceModel <FileHistoryResponse>(); try { var rmCredentials = this.ValidateUserCredentials(request.userName); if (rmCredentials.Success) { response = await this.mainService.GetFileHistoryAsync(request.userName, request.id); } else { response.OnError(rmCredentials); } } catch (Exception ex) { response.OnException(ex); } string uri = Url.Link("FileHistoryApi", new { id = request.id }); var httpResponse = Request.CreateResponse <IResultServiceModel <FileHistoryResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
protected async Task <IResultServiceModel <Customer> > ValidateCustomerUserCredentials(string userName) { IResultServiceModel <Customer> rsm = new ResultServiceModel <Customer>(); try { if (HttpContext.Current.User.Identity.IsAuthenticated) { var claims = (ClaimsIdentity)HttpContext.Current.User.Identity; if (claims.HasClaim("sub", userName)) { //Now check if this user is in a project and which one of active ones rsm = await this.mainService.CheckProjectForLoggedCustomerByName(userName); } else { rsm.OnError(ErrorResources.UserCredentialsInvalid, EnumErrorCode.USER_NOT_VALID); } } else { rsm.OnError(ErrorResources.UserCredentialsInvalid, EnumErrorCode.USER_NOT_VALID); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <Customer> GetById(long id) { IResultServiceModel <Customer> rsm = new ResultServiceModel <Customer>(); try { var item = this.context .Customers .Where(w => w.Id == id) .FirstOrDefault(); if (item != null) { rsm.OnSuccess(item); } else { rsm.OnError(CustomerResources.CustomerNotFoundForAnyActiveProject, EnumErrorCode.CUSTOMER_USER_NOT_FOUND_FOR_ANY_PROJECT); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <WFState> GetSpecificStateByCode(string wfCode, string wfStateCode) { IResultServiceModel <WFState> rsm = new ResultServiceModel <WFState>(); try { var item = this.context .WFWorkflowStates .Where(w => w.WFWorkflow.Code == wfCode && w.WFState.Code == wfStateCode && !w.IsInitial) .FirstOrDefault(); if (item != null) { rsm.OnSuccess(item.WFState); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.ITEM_DOES_NOT_EXIST); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <AppConfiguration> GetValue(string key) { IResultServiceModel <AppConfiguration> rsm = new ResultServiceModel <AppConfiguration>(); try { var item = this.context .AppConfigurations .Where(w => w.Key == key) .FirstOrDefault(); if (item != null) { rsm.OnSuccess(item); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.ITEM_DOES_NOT_EXIST); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public async Task <HttpResponseMessage> MoveFile(WorkflowMoveFileRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("MoveFileApi", new { id = 0 });; string userId = request.userName; IResultServiceModel <WorkflowMoveFileResponse> response = new ResultServiceModel <WorkflowMoveFileResponse>(); try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { response = await this.mainService.MoveWorkflowStateForFileAsync(request); } else { response.OnError(rmCred); } } catch (Exception ex) { response.OnException(ex); } httpResponse = Request.CreateResponse <IResultServiceModel <WorkflowMoveFileResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public IResultServiceModel <WFWorkflow> GetById(long id) { IResultServiceModel <WFWorkflow> rsm = new ResultServiceModel <WFWorkflow>(); try { var item = this.context .WFWorkflows .Where(w => w.Id == id) .FirstOrDefault(); if (item != null) { rsm.OnSuccess(item); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.ITEM_DOES_NOT_EXIST); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public async Task <HttpResponseMessage> GSActivity([FromUri] ProjectGSpaceActivityRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("ProjectGSActivityApi", new { userName = request.userName });; string userId = request.userName; IResultServiceModel <ProjectGSpaceActivityResponse> response = new ResultServiceModel <ProjectGSpaceActivityResponse>(); try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { var rsmCuz = this.mainService.GetCustomerForProjectGeneralSpace(request.pId, request.userName); var cuz = new CustomerPOCO(rsmCuz.Value); response.OnSuccess(new ProjectGSpaceActivityResponse() { list = cuz.Files }); } else { response.OnError(rmCred.ErrorMessage, rmCred.ErrorCode); } } catch (Exception ex) { response.OnException(ex); } httpResponse = Request.CreateResponse <IResultServiceModel <ProjectGSpaceActivityResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public IResultServiceModel <Customer> GetGeneralSpaceCustomerByProject(long projectId) { IResultServiceModel <Customer> rsm = new ResultServiceModel <Customer>(); try { Customer item = this.context .Customers .Where(w => w.ProjectId == projectId && w.SpaceNumber == 0) .FirstOrDefault(); if (item != null) { rsm.OnSuccess(item); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.ITEM_DOES_NOT_EXIST); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <long> GetWorkflowIdByCode(string code) { IResultServiceModel <long> rsm = new ResultServiceModel <long>(); try { long?id = this.context .WFWorkflows .Where(w => w.Code == code) .Select(s => s.Id) .SingleOrDefault(); if (id.HasValue) { rsm.OnSuccess(id.Value); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.ITEM_DOES_NOT_EXIST); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <long> GetMostRecent() { IResultServiceModel <long> rsm = new ResultServiceModel <long>(); try { var item = this.context .Projects .OrderByDescending(o => o.Id) .FirstOrDefault(); if (item != null) { rsm.OnSuccess(item.Id); } else { rsm.OnError(ErrorResources.NoProjectsAlreadyCreated, EnumErrorCode.ZERO_PROJECTS); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public async Task <HttpResponseMessage> Get() { HttpResponseMessage httpResponse = null; string uri = string.Empty; IResultServiceModel <AlfredDefaultPlatformParametersResponse> response = new ResultServiceModel <AlfredDefaultPlatformParametersResponse>(); Task <IResultServiceModel <AlfredDefaultPlatformParametersResponse> > taskResponse = null; try { taskResponse = this.mainService.GetDefaultPlatformParametersAsync(); } catch (Exception ex) { response.OnException(ex); } uri = Url.Link("AlfredGetApi", new { id = 0 }); if (taskResponse != null) { response = await taskResponse; } else { response.OnSuccess(new AlfredDefaultPlatformParametersResponse() { publicKey = "", totalStands = 1 }); } httpResponse = Request.CreateResponse <IResultServiceModel <AlfredDefaultPlatformParametersResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public async Task <IResultServiceModel <Project> > AddProjectByUserAsync(ProjectItemRequest model) { IResultServiceModel <Project> rsm = new ResultServiceModel <Project>(); //get the user User user = null; string roleFlags = string.Empty; try { user = await this.accountService.FindUserByUserNameOrEmailAsync(model.userName); /* 1st => data validation */ var rm = this.CheckProjectForAdding(model); if (rm.Success) { var project = new Project(); model.CopyTo(project); this.projectRepository.Add(project); var rmAdd = this.projectRepository.Save(); if (rmAdd.Success) { rmAdd = this.CompleteProjectCreation(project, model.userName); if (rmAdd.Success) { rmAdd = this.GrantUsersInProject(project, user); if (rmAdd.Success) { rsm.OnSuccess(project); } else { rsm.OnError(rmAdd.ErrorMessage, rmAdd.ErrorCode); } } else { rsm.OnError(rmAdd.ErrorMessage, rmAdd.ErrorCode); } } else { rsm.OnError(rmAdd.ErrorMessage, rmAdd.ErrorCode); } } else { rsm.OnError(rm.ErrorMessage, rm.ErrorCode); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <WFTransition> FindByWorkflowAndEndPointStates(long originWFStateId, long destinationWFStateId, long wfWorkflowId, long wfWorkflowVersion) { IResultServiceModel <WFTransition> rsm = new ResultServiceModel <WFTransition>(); try { var tr = this.context .WFWorkflowTransitions .Where(w => w.WFWorkflowId == wfWorkflowId && w.WFWorkflowVersion == wfWorkflowVersion && w.WFWorkflowStateOrigin.WFStateId == originWFStateId && w.WFWorkflowStateDestination.WFStateId == destinationWFStateId) .FirstOrDefault(); if (tr != null) { rsm.OnSuccess(tr.WFTransition); } else { rsm.OnError(ErrorResources.ItemDoesNotExist, EnumErrorCode.TRANSITION_NOT_FOUND); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public async Task <HttpResponseMessage> Post(ProjectFilesListRequest request) { //var request = new ProjectFilesListRequest() { userName = userName, projectId = 0 }; HttpResponseMessage httpResponse = null; string uri = Url.Link("FilesApi", new { id = 0 });; string userId = request.userName; IResultServiceModel <ProjectFilesListResponse> response = new ResultServiceModel <ProjectFilesListResponse>(); try { var rmsList = await this.customerFileService.GetCustomerFilesByProjectAsync(request.userName, request.projectId); if (rmsList.Success) { response.Value = new ProjectFilesListResponse(); response.Value.fileList = rmsList.Value; } else { response.OnError(rmsList.ErrorMessage, rmsList.ErrorCode); } } catch (Exception ex) { response.OnException(ex); } httpResponse = Request.CreateResponse <IResultServiceModel <ProjectFilesListResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public IResultServiceModel <WFState> GetStateByWorkflowAndCode(long wfWorkflowId, long wfWorkflowVersion, string movementCode) { IResultServiceModel <WFState> rsm = new ResultServiceModel <WFState>(); try { movementCode = movementCode.ToUpper(); var wfState = this.context .WFWorkflowStates .Where(w => w.WFWorkflowId == wfWorkflowId && w.WFWorkflowVersion == wfWorkflowVersion && w.WFState.Code == movementCode) .Select(s => s.WFState) .FirstOrDefault(); if (wfState != null) { rsm.OnSuccess(wfState); } else { rsm.OnError(ErrorResources.WFStateNotFound, EnumErrorCode.STATE_NOT_FOUND); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public IResultServiceModel <IEnumerable <WFFileState> > GetListByFileId(long id) { IResultServiceModel <IEnumerable <WFFileState> > rsm = new ResultServiceModel <IEnumerable <WFFileState> >(); try { var list = this.context .WFFileStates .Where(w => w.EntityId == id) .OrderByDescending(o => o.TS) .ToList(); if (list != null) { rsm.OnSuccess(list); } else { rsm.OnError(HistoryResources.NoHistoryFound); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public async Task <HttpResponseMessage> DeleteItem([FromUri] ProjectItemRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("ProjectDeleteApi", new { id = request.id }); string userId = request.userName; IResultServiceModel <ProjectItemResponse> response = new ResultServiceModel <ProjectItemResponse>(); if (request.id <= 0) { response.OnError(ProjectResources.ErrorItemDoesNotExist_OnDelete, EnumErrorCode.ITEM_DOES_NOT_EXIST); } else { try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { IResultModel rmDelete = await this.projectService.DeleteProjectByUserAsync(request); if (rmDelete.Success) { response.OnSuccess(new ProjectItemResponse() { item = new ProjectPOCO() { Id = request.id } }); } else { response.OnError( ErrorResources.ModelStateErrors_Format.sf(rmDelete.ErrorMessage), rmDelete.ErrorCode ); } } else { response.OnError(rmCred.ErrorMessage, rmCred.ErrorCode); } } catch (Exception ex) { response.OnException(ex); } } httpResponse = Request.CreateResponse <IResultServiceModel <ProjectItemResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public async Task <HttpResponseMessage> Excel([FromBody] ProjectExcelRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("ProjectExcelApi", new { id = request.id }); string userId = request.userName; IResultServiceModel <ProjectExcelResponse> response = new ResultServiceModel <ProjectExcelResponse>(); try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { IResultServiceModel <string> rmsGUID; rmsGUID = this.miscService.GenerateDownloadExcelFileId(request.id); if (rmsGUID.Success) { var host = this.GetBaseUrl(); host = "{0}api/Project/DownloadExcel?guid={1}".sf(host, rmsGUID.Value); var resp = new ProjectExcelResponse() { url = host }; response.OnSuccess(resp); } else { response.OnError(rmsGUID.ErrorMessage, rmsGUID.ErrorCode); } } else { response.OnError(rmCred.ErrorMessage, rmCred.ErrorCode); } } catch (Exception ex) { response.OnException(ex); } httpResponse = Request.CreateResponse <IResultServiceModel <ProjectExcelResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
public IResultServiceModel <IEnumerable <Project> > GetActiveProjects() { IResultServiceModel <IEnumerable <Project> > rsm = new ResultServiceModel <IEnumerable <Project> >(); try { var list = this.context.Projects.OrderByDescending(o => o.StartDate); return(rsm.OnSuccess(list)); } catch (Exception ex) { return(rsm.OnException(ex)); } }
public IResultServiceModel <IEnumerable <AppConfiguration> > GetOnlyPlatformParams() { var allowed = new string[] { EnumAppConfigurationKeyDefinition.PublicKey, EnumAppConfigurationKeyDefinition.DefaultTotalStandsPerEvent }; IResultServiceModel <IEnumerable <AppConfiguration> > rsm = new ResultServiceModel <IEnumerable <AppConfiguration> >(); try { var list = this.context.AppConfigurations.Where(w => allowed.Contains(w.Key)); rsm.OnSuccess(list); } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
/// <summary> /// Gets all. /// </summary> /// <returns></returns> public virtual IResultServiceModel <IEnumerable <T> > GetAll() { IResultServiceModel <IEnumerable <T> > rv = new ResultServiceModel <IEnumerable <T> >(); try { return(rv.OnSuccess( this.context .Set <T>() )); } catch (Exception ex) { return(rv.OnException(ex)); } }
public IResultServiceModel <FileHistoryResponse> GetFileHistoryByFileAndUser(long fileId, User user, bool isOnlyCustomer) { IResultServiceModel <FileHistoryResponse> rsm = new ResultServiceModel <FileHistoryResponse>(); FileHistoryResponse response = new FileHistoryResponse(); bool authorized = true; try { var rmFile = this.fileRepository.Find(fileId); if (rmFile.Success) { var file = rmFile.Value; if (isOnlyCustomer) { //Authorization depends on whether the user is the owner or not authorized = (file.Customer.UserId == user.Id); } if (authorized) { var rmStates = this.wfFileStateRepository.GetListByFileId(fileId); response.File = new FilePOCO(file); if (rmStates.Success) { response.States = rmStates.Value.Select(s => new WFFileStatePOCO(s)); } else { response.States = Enumerable.Empty <WFFileStatePOCO>(); } rsm.OnSuccess(response); } } else { rsm.OnError(CustomerResources.UserHasNotAuthorizationForThisFileHistory); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
/// <summary> /// Counts the number of the elements from this entity that are in the current context. /// </summary> /// <returns></returns> public async Task <IResultServiceModel <int> > CountAsync() { IResultServiceModel <int> rv = new ResultServiceModel <int>(); try { return(rv.OnSuccess( await this.context .Set <T>() .CountAsync() )); } catch (Exception ex) { return(rv.OnException(ex)); } }
/// <summary> /// Creates an instance. /// </summary> /// <returns></returns> public virtual IResultServiceModel <T> Create() { IResultServiceModel <T> rv = new ResultServiceModel <T>(); try { return(rv.OnSuccess( this.context .Set <T>() .Create() )); } catch (Exception ex) { return(rv.OnException(ex)); } }