public Response Login(string email, string password)
        {
            if (email == null || password == null)
            {
                return(responseFactory.CreateResponse("Error: invalid email or password", ResponseStatus.BADREQUEST));
            }

            response = new Response();

            try
            {
                response = userDao.GetUserByEmail(email);
            }
            catch (Exception exception)
            {
                return(responseFactory.CreateResponse(exception.Message, ResponseStatus.EXCEPTION));
            }

            if (response.responseStatus != ResponseStatus.OK)
            {
                return(responseFactory.CreateResponse(response.message, ResponseStatus.NOTFOUND));
            }
            if (response.user.password != password)
            {
                return(responseFactory.CreateResponse("Error: invalid password", ResponseStatus.BADREQUEST));
            }

            return(response);
        }
Exemplo n.º 2
0
        public IHttpActionResult Login([FromBody] UserLoginRequest user)
        {
            try
            {
                if (user == null || user.RequiredFieldsAreNullOrBlank)
                {
                    return(BadRequest("Some or all of the data required for user registration is blank or missing. Please try again."));
                }
                var result = _users.Login(user);

                if (result.Status == RepositoryActionStatus.Updated)
                {
                    var authenticatedUser = _userFactory.CreateAuthenticatedUser(result.Entity);
                    var response          = _responseFactory.CreateResponse(authenticatedUser);
                    return(Ok(response));
                }
                else if (result.Status == RepositoryActionStatus.NotFound)
                {
                    return(NotFound());                    //user was not found or passwords did not match
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(InternalServerError());
            }
        }
Exemplo n.º 3
0
        public new static async Task <Response <Order> > CreateAsync(Order order, bool refreshFromDb = false, IList <string> navigationProperties = null)
        {
            Parallel.ForEach(order.OrderItems.Where(orderItem => orderItem.Id == Guid.Empty), orderItem => { orderItem.Id = Guid.NewGuid(); });

            if (!SalesValidator.ValidateOrder(order))
            {
                return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.ErrorInvalidInput));
            }

            order.Date   = DateTime.Now;
            order.Status = OrderStatus.Created.ToInt();

            using (var orderRepository = DataLayerUnitOfWork.Repository <OrderRepository>())
            {
                var createdOrder =
                    await orderRepository.CreateAsync(order.CopyTo <DataLayer.Order>(), refreshFromDb, navigationProperties).ConfigureAwait(false);

                if (createdOrder == null)
                {
                    return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.Error));
                }

                return(ResponseFactory <Order> .CreateResponse(true, ResponseCode.Success, createdOrder.CopyTo <Order>()));
            }
        }
Exemplo n.º 4
0
        public virtual async Task <JsonResult> Login(LoginViewModel model, string returnUrl)
        {
            var response = ResponseFactory.CreateResponse <StringWrapper>(false, (int)ResponseCode.ErrorAnErrorOccurred);

            if (!ModelState.IsValid)
            {
                return(Json(ResponseFactory.ErrorReponse));
            }

            var result = await CheckUserCredentials(model.Email, model.Password, model.RememberMe).ConfigureAwait(false);

            if (result)
            {
                return(Json(ResponseFactory.CreateResponse <StringWrapper>(true, (int)ResponseCode.Success)));
            }

            //SignInStatus result = SignInStatus.Failure;
            //result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
            //if(result != SignInStatus.Failure)
            //{
            //    response = ResponseFactory.Success<StringWrapper>((int)ResponseCode.Success);
            //}

            return(Json(response));
        }
Exemplo n.º 5
0
        public IActionResult SendMessage(string body, string receiver)
        {
            if (string.IsNullOrEmpty(body) || string.IsNullOrEmpty(receiver))
            {
                return(BadRequest());
            }

            var receiverUser = m_UserRepository.GetByUserName(receiver);
            var unWantsMe    = m_BlockingRepository.GetUnwantsMe(CurrentUser.UserID);

            //Blocked user can't send messages. I thought user who blocks someone should be invisible for them
            if (receiverUser == null || unWantsMe.Any(u => u.UserID == receiverUser.UserID))
            {
                return(NotFound(ResponseFactory.CreateResponse("User Not Found")));
            }

            var message = m_ModelFactory.CreateMessage(body, CurrentUser.UserID, receiverUser.UserID, m_DateTimseService.Now());

            if (TryValidateModel(message))
            {
                m_messageRepository.Insert(message);
            }
            else
            {
                return(BadRequest(ResponseFactory.CreateResponse(ModelState)));
            }

            m_Logger.LogInformation("Message sent to user {0} \n Message Body: {1} \n from user {0}", receiverUser.UserID, message.Body, CurrentUser.UserID);
            return(Ok(ResponseFactory.CreateResponse(message)));
        }
Exemplo n.º 6
0
        public IActionResult Delete(string username)
        {
            if (string.IsNullOrEmpty(username))
            {
                return(BadRequest());
            }

            var userBlocked = m_UserRepository.GetByUserName(username);

            if (userBlocked == null)
            {
                return(NotFound(ResponseFactory.CreateResponse("User Not Found")));
            }

            if (!m_BlockingRepository.IsBlockingExist(CurrentUser.UserID, userBlocked.UserID))
            {
                return(NotFound(ResponseFactory.CreateResponse("Blocking Not Found")));
            }

            var blocking = m_ModelFactory.CreateBlocking(CurrentUser.UserID, userBlocked.UserID);

            m_BlockingRepository.Delete(blocking);

            return(Ok());
        }
Exemplo n.º 7
0
        public IActionResult Put(string username)
        {
            if (string.IsNullOrEmpty(username))
            {
                return(BadRequest());
            }

            var userBlocked = m_UserRepository.GetByUserName(username);

            if (userBlocked == null)
            {
                return(NotFound(ResponseFactory.CreateResponse("User Not Found")));
            }

            var blocking = m_ModelFactory.CreateBlocking(CurrentUser.UserID, userBlocked.UserID);

            if (TryValidateModel(blocking))
            {
                m_BlockingRepository.Insert(blocking);
            }
            else
            {
                return(BadRequest(ResponseFactory.CreateResponse(ModelState)));
            }

            return(Ok());
        }
Exemplo n.º 8
0
        private IDecodeResponse HandleGetInternal(IDecodeRequest request, WeatherProductType productType)
        {
            var             parser = ParserFactory.CreateParser(request, productType);
            IWeatherProduct result = parser.Parse();

            return(ResponseFactory.CreateResponse(result));
        }
        public Response DeleteProject(int id)
        {
            magmaDbContext.Remove <Project>(GetProjectById(id).project);

            magmaDbContext.SaveChanges();

            return(responseFactory.CreateResponse("Success: removed project", ResponseStatus.OK));
        }
        private async Task <Response> ProcessNotification(string notification)
        {
            var response = ResponseFactory.CreateResponse(notification, this);

            await TriggerActionsFromNotification(response);

            return(response);
        }
Exemplo n.º 11
0
        public Response DeleteAudioEffect(int id)
        {
            magmaDbContext.Remove <AudioEffect>(GetAudioEffectById(id).audioEffect);

            magmaDbContext.SaveChanges();

            return(responseFactory.CreateResponse("Success: removed audio effect", ResponseStatus.OK));
        }
        public Response DeletePlugin(int id)
        {
            magmaDbContext.Remove <Plugin>(GetPluginById(id).plugin);

            magmaDbContext.SaveChanges();

            return(responseFactory.CreateResponse("Success: deleted plugin", ResponseStatus.OK));
        }
Exemplo n.º 13
0
        public Response DeleteSynthesizer(int id)
        {
            magmaDbContext.Remove <Synthesizer>(GetSynthesizerById(id).synthesizer);

            magmaDbContext.SaveChanges();

            return(responseFactory.CreateResponse("Success: removed synthesizer", ResponseStatus.OK));
        }
        public Response DeleteUser(int id)
        {
            magmaDbContext.Remove <User>(GetUserById(id).user);

            magmaDbContext.SaveChanges();

            return(responseFactory.CreateResponse("Success: deleted user", ResponseStatus.OK));
        }
Exemplo n.º 15
0
        public Response DeleteTrack(int id)
        {
            magmaDbContext.Remove <Track>(GetTrackById(id).track);

            magmaDbContext.SaveChanges();

            return(responseFactory.CreateResponse("Success: removed track", ResponseStatus.OK));
        }
Exemplo n.º 16
0
        public Response GetProjectById(int id)
        {
            if (id == 0)
            {
                return(responseFactory.CreateResponse("Error: input parameter is null", ResponseStatus.BADREQUEST));
            }

            response = new Response();

            try
            {
                response = playgroundDao.GetProjectById(id);
            }
            catch (Exception exception)
            {
                return(responseFactory.CreateResponse(exception.Message, ResponseStatus.EXCEPTION));
            }

            if (response.project.id == 0)
            {
                return(responseFactory.CreateResponse("Error: project not found", ResponseStatus.NOTFOUND));
            }

            return(response);
        }
Exemplo n.º 17
0
        public static async Task <Response> DeleteAsync(Guid id)
        {
            using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>())
            {
                var result = await repository.DeleteAsync(id).ConfigureAwait(false);

                return(ResponseFactory.CreateResponse(result, result ? ResponseCode.Success : ResponseCode.ErrorAnErrorOccurred));
            }
        }
Exemplo n.º 18
0
        public static async Task <Response> DeleteAsync(Guid id)
        {
            using (var repository = DataLayerUnitOfWork.Repository <TRepo>())
            {
                var result = await repository.DeleteAsync(id).ConfigureAwait(false);

                return(ResponseFactory.CreateResponse(result, result ? ResponseCode.Success : ResponseCode.ErrorInvalidInput));
            }
        }
        public static async Task <Response <TOutput> > ExecuteGetAsync <TOutput>(string relativeUrl, Dictionary <string, string> parameters)
            where TOutput : class, new()
        {
            var url = relativeUrl;

            if (string.IsNullOrWhiteSpace(url))
            {
                return(ResponseFactory.CreateResponse <TOutput>(false, 27));
            }

            using (var client = new HttpClient())
            {
                SetupHttpClient(client);

                try
                {
                    if (parameters != null && parameters.Count > 0)
                    {
                        var queryString = GenerateQueryString(parameters);
                        if (!string.IsNullOrWhiteSpace(queryString))
                        {
                            url = $"{url}{queryString}";
                        }
                    }

                    url = $"{Constants.WEB_API_BASE_ROOT_URL}/api/{url}";

                    Debug.WriteLine("____________________________________________________");
                    Debug.WriteLine("Calling endpoint: {0}", url);
                    Debug.WriteLine("____________________________________________________");

                    var response = await client.GetAsync(url).ConfigureAwait(false);

                    if (response != null && response.IsSuccessStatusCode)
                    {
                        var stringfiedContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        Debug.WriteLine("____________________________________________________");
                        Debug.WriteLine("Got answer from endpoint {0}: {1}", url, stringfiedContent);
                        Debug.WriteLine("____________________________________________________");

                        var deserializedData = string.IsNullOrWhiteSpace(stringfiedContent)
                            ? ResponseFactory.CreateResponse <TOutput>(false, 19)
                            : DeserializeResponse <TOutput>(stringfiedContent);

                        return(deserializedData);
                    }
                }
                catch (Exception ex)
                {
                    MvxTrace.Warning(ex.ToString());
                }
            }

            return(ResponseFactory.CreateResponse <TOutput>(false, 19));
        }
Exemplo n.º 20
0
        public async Task <IActionResult> GetCustomer(Guid id)
        {
            var customer = await _context.Customers.Include(x => x.Notes).FirstOrDefaultAsync(c => c.Id == id);

            if (customer is null)
            {
                return(NotFound());
            }
            return(Ok(ResponseFactory.CreateResponse(customer)));
        }
Exemplo n.º 21
0
        public IActionResult Register([Bind("UserName,EmailAddress,Password")] User user)
        {
            User result = m_UserRepository.Insert(user);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ResponseFactory.CreateResponse(ModelState)));
            }
            m_Logger.LogInformation("User Registered with Id: {0}", user.UserID);
            return(Ok(ResponseFactory.CreateResponse(user)));
        }
Exemplo n.º 22
0
        public virtual async Task <TResult> Handle(TRequest request, CancellationToken cancellationToken)
        {
            var httpResponse = await SendRequest(request, cancellationToken)
                               .ConfigureAwait(continueOnCapturedContext: false);

            var logicalResponse = await ResponseFactory.CreateResponse <TResult>(httpResponse)
                                  .ConfigureAwait(continueOnCapturedContext: false);

            logicalResponse.ThrowExceptionOnUnsuccessfulStatus();
            return(logicalResponse.Value);
        }
Exemplo n.º 23
0
        public static async Task <Response> DeleteAsync(IList <TModel> modelCollection)
        {
            using (var repository = DataLayerUnitOfWork.Repository <TRepo>())
            {
                var entityCollection = modelCollection.CopyTo <TEntity>();

                var result = await repository.DeleteAsync(entityCollection).ConfigureAwait(false);

                return(ResponseFactory.CreateResponse(result, result ? ResponseCode.Success : ResponseCode.ErrorInvalidInput));
            }
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var modelState = context.ModelState;

            if (!modelState.IsValid)
            {
                context.Result = new BadRequestObjectResult(ResponseFactory.CreateResponse(context.ModelState));
            }

            base.OnActionExecuting(context);
        }
Exemplo n.º 25
0
        public static Response <TDataAccessModel> RestoreState(TDataAccessModel entityFromDb, TDataAccessModel entityToRestore)
        {
            using (var repository = RepoUnitOfWork.CreateTrackingRepository <TRepo>())
            {
                entityToRestore = entityFromDb;

                var result = repository.Update(entityToRestore, true);

                return(ResponseFactory.CreateResponse(result != null, result != null ? ResponseCode.Success : ResponseCode.ErrorAnErrorOccurred, result));
            }
        }
Exemplo n.º 26
0
        public async Task <JsonResult> GetUserData()
        {
            var identity = GetIdentity();

            var model = await UserCore.GetUserData(identity.AspNetUserId).ConfigureAwait(false);

            if (model == null)
            {
                return(Json(ResponseFactory.ErrorReponse));
            }

            return(Json(ResponseFactory.CreateResponse(true, (int)ResponseCode.Success, model)));
        }
Exemplo n.º 27
0
        public async Task <IHttpActionResult> GetAllForClient(Guid clientId)
        {
            try
            {
                var response = await PayrollCore.GetAllForClient(clientId).ConfigureAwait(false);

                return(Ok(response));
            }
            catch (Exception)
            {
                return(Ok(ResponseFactory <IList <Payroll> > .CreateResponse(false, ResponseCode.Error)));
            }
        }
Exemplo n.º 28
0
        public static async Task <Response <IList <TModel> > > GetAllAsync(IList <string> navigationProperties = null)
        {
            using (var repository = DataLayerUnitOfWork.Repository <TRepo>())
            {
                var entities = await repository.GetAllAsync(navigationProperties).ConfigureAwait(false);

                if (entities == null)
                {
                    ResponseFactory <IList <TModel> > .CreateResponse(false, ResponseCode.Error);
                }

                return(ResponseFactory <IList <TModel> > .CreateResponse(true, ResponseCode.Success, entities.CopyTo <TModel>()));
            }
        }
Exemplo n.º 29
0
        public static async Task <Response <IList <Payroll> > > GetAllForClient(Guid clientId, IList <string> navigationProperties = null)
        {
            using (var payrollRepository = DataLayerUnitOfWork.Repository <PayrollRepository>())
            {
                var payrolls = await payrollRepository.GetAllForClient(clientId, navigationProperties).ConfigureAwait(false);

                if (payrolls == null)
                {
                    return(ResponseFactory <IList <Payroll> > .CreateResponse(false, ResponseCode.ErrorNotFound));
                }

                return(ResponseFactory <IList <Payroll> > .CreateResponse(true, ResponseCode.Success, payrolls.CopyTo <Payroll>()));
            }
        }
Exemplo n.º 30
0
        private void HandleResponses()
        {
            SortedList modules = new SortedList();

            while (true)
            {
                string responseStr = inputStream.ReadToFirstWS();
                if (LOGGER.IsDebugEnabled)
                {
                    LOGGER.Debug("Response : " + responseStr);
                }

                if (responseStr.Length == 0)
                {
                    SendMessage("server timed out");
                    break;
                }

                IResponse response =
                    ResponseFactory.CreateResponse(responseStr.Substring(0, responseStr.Length - 1));
                if (LOGGER.IsDebugEnabled)
                {
                    LOGGER.Debug("cvs server: " + response);
                }

                if (response == null)
                {
                    if (responseStr.EndsWith(" "))
                    {
                        inputStream.ReadLine();
                    }
                    break;
                }
                response.Process(inputStream, this);
                if (response.IsTerminating)
                {
                    break;
                }
                if (null != response && null != response.ResponseString)
                {
                    try {
                        this.ResponseMessageEvent(this, new MessageEventArgs(response,
                                                                             response.GetType().Name));
                    } catch (NullReferenceException) {
                        LOGGER.Debug("No one is listening to the response message event.");
                    }
                }
            }
        }