Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
        private async void Payment()
        {
            try
            {
                IsPaymentEnabled = false;
                ResultServiceModel <PaymentViewModel> paymentResult = await _transactionServices.Payment(Email, MerchantAccountNumber, Amount, TransactionReference);

                if (paymentResult == null || paymentResult.IsError)
                {
                    //Application.Current.MainPage.DisplayAlert("Error", "Payment Fail", "Ok");
                    ErrorViewModel errorView = new ErrorViewModel("ทำรายการไม่สำเร็จ", (int)EW_ErrorTypeEnum.Error);
                    PopupNavigation.Instance.PushAsync(new Error(errorView));
                }
                else
                {
                    CreateDate = paymentResult.Model.CreateDatetime;
                    Reference  = paymentResult.Model.Reference;
                    PopupNavigation.Instance.PopAllAsync();
                    PopupNavigation.Instance.PushAsync(new Views.ScanToPayThree(this));
                }
                IsPaymentEnabled = true;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Example #16
0
        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);
        }
Example #17
0
        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);
        }
Example #18
0
        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);
        }
Example #19
0
        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);
        }
Example #20
0
        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);
        }
Example #21
0
        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);
        }
Example #22
0
        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);
        }
Example #23
0
        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);
        }
Example #24
0
        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);
        }
Example #25
0
        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);
        }
Example #26
0
        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);
        }
Example #27
0
        public async Task <ResultServiceModel <GetTokenByRefreshTokenViewModel> > GetAccessToken()
        {
            ResultServiceModel <GetTokenByRefreshTokenViewModel> resultService = new ResultServiceModel <GetTokenByRefreshTokenViewModel>();

            try
            {
                string url = Helper.BaseUrl + "auth/GetTokenByRefreshToken";

                HttpClient client = new HttpClient();

                string refreshToken = "";

                string email = "";

                try
                {
                    refreshToken = SecureStorage.GetAsync("RefreshToken").Result;
                    email        = SecureStorage.GetAsync("Email").Result;
                }
                catch (Exception e)
                {
                    CloseApp();
                }

                GetTokenByRefreshTokenCommand model = new GetTokenByRefreshTokenCommand
                {
                    Email = email,

                    RefreshToken = refreshToken
                };

                HttpContent content = GetHttpContent(model);

                var result = await client.PostAsync(url, content);

                if (result.IsSuccessStatusCode)
                {
                    var json_result = await result.Content.ReadAsStringAsync();

                    GetTokenByRefreshTokenViewModel obj = GetModelFormResult <GetTokenByRefreshTokenViewModel>(json_result);

                    resultService.IsError = false;

                    resultService.Model = obj;

                    return(resultService);
                }
                else
                {
                    client.Dispose();
                    CloseApp();
                }
            }
            catch (Exception e)
            {
                resultService.IsError = true;
            }
            return(resultService);
        }
        async Task Login()
        {
            IsProgress = true;
            try
            {
                if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
                {
                    ResultServiceModel <LoginUserAndPassViewModel> loginResult = await _authService.LoginUserAndPass(Username, Password);

                    if (loginResult == null || loginResult.IsError)
                    {
                        ErrorViewModel errorView = new ErrorViewModel("ไม่สามารถเชื่อมต่อกับระบบได้");
                        IsProgress = false;
                        await PopupNavigation.Instance.PushAsync(new Error(errorView));
                    }
                    else
                    {
                        try
                        {
                            var checkRole = int.Parse(loginResult.Model.Account.Substring(0, 2)) == (int)EW_Enumerations.EW_UserTypeEnum.Admin;
                            if (checkRole)
                            {
                                IsProgress = false;
                                var successSave = await StoreValue(loginResult.Model);

                                if (successSave)
                                {
                                    App.Email = Username;
                                    Application.Current.MainPage = new NavigationPage(new AdminTabbedPage());
                                }
                            }
                            else
                            {
                                ErrorViewModel errorView = new ErrorViewModel("ไม่ได้รับอนุญาติให้เข้าใช้ระบบ", (int)EWalletV2.Api.ViewModels.EW_Enumerations.EW_ErrorTypeEnum.Warning);
                                IsProgress = false;
                                await PopupNavigation.Instance.PushAsync(new Error(errorView));
                            }
                        }
                        catch (Exception e)
                        {
                            ErrorViewModel errorView = new ErrorViewModel("ไม่สามารถเชื่อมต่อกับระบบได้");
                            IsProgress = false;
                            await PopupNavigation.Instance.PushAsync(new Error(errorView));
                        }
                    }
                }
                else
                {
                    ErrorViewModel errorView = new ErrorViewModel("โปรดกรอก Username และ Password", (int)EWalletV2.Api.ViewModels.EW_Enumerations.EW_ErrorTypeEnum.Warning);
                    IsProgress = false;
                    await PopupNavigation.Instance.PushAsync(new Error(errorView));
                }
            }
            catch (Exception e)
            {
            }
        }
Example #29
0
        public async Task GetTotalBalance()
        {
            ResultServiceModel <AccountViewModel> account = await _userService.GetBalance(Email);

            if (account != null)
            {
                Balance = account.Model.Balance;
            }
        }
Example #30
0
        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);
        }