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 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); }
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 <long> CheckDownloadExcelFileId(string guid) { IResultServiceModel <long> rm = new ResultServiceModel <long>(); var rsm = this.miscRepository.GetByKeyWithValue(MiscKeyEnum.EXCEL_DOWNLOAD_GUID.ToString(), guid); if (rsm.Success) { if (rsm.Value.Limit > DateTime.Now) { var info = Newtonsoft.Json.JsonConvert.DeserializeObject <ProjectExcelFileInfo>(rsm.Value.Value); rm.OnSuccess(info.ProjectId); } else { rm.OnError(MiscResources.TimeForDownloadThisExcelFileIsOut); } } else { rm.OnError(rm.ErrorMessage, rm.ErrorCode); } return(rm); }
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 IResultServiceModel <WFFileState> SetStateForFile(long fileId, string userId, string wfStateCode, string userComment = null) { IResultServiceModel <WFFileState> rm = new ResultServiceModel <WFFileState>(); var now = DateTime.Now; //Get Default Workflow For Files var wfCode = this.appConfigurationService.DefaultFileWorkflowCode; var rmIS = this.wfStateRepository.GetSpecificStateByCode(wfCode, wfStateCode); if (rmIS.Success) { var state = rmIS.Value; var fHis = new WFFileState() { EntityId = fileId, UserId = userId, WFStateId = rmIS.Value.Id, TS = now }; if (string.IsNullOrEmpty(userComment)) { userComment = state.Name; } fHis.Notes.Add(new WFFileStateNote() { UserId = userId, TS = now, Comment = userComment }); this.wfFileStateRepository.Add(fHis); var rmSave = this.wfFileStateRepository.Save(); if (rmSave.Success) { rm = this.wfFileStateRepository.GetById(fHis.Id); } else { rm.OnError(rmSave.ErrorMessage, rmSave.ErrorCode); } } else { rm.OnError(rmIS.ErrorMessage, rmIS.ErrorCode); } return(rm); }
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 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> 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 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 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 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 async Task <HttpResponseMessage> RegisterReservation(CustomerRegistrationRequest request) { HttpResponseMessage httpResponse = null; Customer cuz = null; string uri = string.Empty; var rmsCustomer = await this.mainService.RegisterNewCustomerInProjectAsync(request, false); IResultServiceModel <CustomerRegistrationResponse> response = new ResultServiceModel <CustomerRegistrationResponse>(); if (rmsCustomer.Success) { cuz = rmsCustomer.Value; this.mainService.SendEmailNewCustomerSignUp(cuz, this.GetBaseUrl()); response.OnSuccess(new CustomerRegistrationResponse() { CustomerId = cuz.Id, ProjectId = rmsCustomer.Value.ProjectId }); } else { response.OnError(rmsCustomer.ErrorMessage, rmsCustomer.ErrorCode); } httpResponse = Request.CreateResponse <IResultServiceModel <CustomerRegistrationResponse> >(HttpStatusCode.Created, response); uri = Url.Link("RegisterReservationApi", new { id = response.ErrorCode }); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }
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 <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 <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 <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 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); }
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 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 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 <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 <WFFileState> GetById(long id) { IResultServiceModel <WFFileState> rsm = new ResultServiceModel <WFFileState>(); var item = this.context .WFFileStates .Include(i => i.WFState) .Include(i => i.User) .Where(w => w.Id == id) .FirstOrDefault(); if (item != null) { if (item.WFState == null) { item.WFState = this.context.WFStates.Find(item.WFStateId); } rsm.OnSuccess(item); } else { rsm.OnError(ErrorResources.ItemDoesNotExist); } 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 IResultServiceModel <Customer> GetCustomerbyProjectCode(string signUpCode, bool mustBeFree = true) { IResultServiceModel <Customer> rsm = new ResultServiceModel <Customer>(); signUpCode = signUpCode.ToUpper(); try { var customer = this.context.Customers .Where(w => w.SignUpCode == signUpCode) .FirstOrDefault(); if (customer != null) { if (mustBeFree) { if (string.IsNullOrWhiteSpace(customer.Email)) { rsm.OnSuccess(customer); } else { rsm.OnError(CustomerResources.CustomerCodeHasBeenUsed); } } else { rsm.OnSuccess(customer); } } else { rsm.OnError(CustomerResources.CustomerCodeDoesNotExist); } } catch (Exception ex) { rsm.OnException(ex); } return(rsm); }
public async Task <HttpResponseMessage> GetItem([FromUri] ProjectItemRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("ProjectItemApi", new { id = request.id });; string userId = request.userName; IResultServiceModel <ProjectItemResponse> response = new ResultServiceModel <ProjectItemResponse>(); try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { var rmsItem = await this.projectService.GetProjectByIdAndUserAsync(request.userName, request.id); if (rmsItem.Success) { response.OnSuccess(new ProjectItemResponse() { item = new ProjectPOCO(rmsItem.Value) }); } else { response.OnError(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 async Task <HttpResponseMessage> ChangeSpaceStatus([FromBody] ChangeSpaceStatusRequest request) { HttpResponseMessage httpResponse = null; string uri = Url.Link("ProjectChangeSpaceStatusApi", new { customerId = request.customerId, currentStatus = request.currentStatus, email = request.email, index = request.index, newStatus = request.newStatus, password = request.password, projectId = request.projectId, registered = request.registered, userName = request.userName }); string userId = request.userName; IResultServiceModel <ChangeSpaceStatusResponse> response = new ResultServiceModel <ChangeSpaceStatusResponse>(); if (!ModelState.IsValid) { response.OnError(this.GetErrorsFromModelState(), EnumErrorCode.VALIDATION_ERROR); } else { try { var rmCred = this.ValidateUserCredentials(request.userName); if (rmCred.Success) { response = await this.mainService.ChangeCustomerSpaceStatus(request, this.GetBaseUrl()); } else { response.OnError(rmCred.ErrorMessage, rmCred.ErrorCode); } } catch (Exception ex) { response.OnException(ex); } } httpResponse = Request.CreateResponse <IResultServiceModel <ChangeSpaceStatusResponse> >(HttpStatusCode.Created, response); httpResponse.Headers.Location = new Uri(uri); return(httpResponse); }