public ActionResult Index()
        {
            var            repository = new ClientRepo(context);
            IList <Client> clients    = repository.GetClients();

            return(View("Index", clients));
        }
Exemple #2
0
        public string Login(string login, string password, string senderName)
        {
            string result = string.Empty;

            if (Membership.ValidateUser(login, password))
            {
                MembershipUser mu     = Membership.GetUser(login);
                ClientModel    client = ClientRepo.GetClientProjected((Guid)mu.ProviderUserKey);

                string gateSessionKey = _gateService.Login(Properties.Settings.Default.GateUserName, Properties.Settings.Default.GatePassword, senderName);
                if (!string.IsNullOrEmpty(gateSessionKey) && client != null && client.Id != null)
                {
                    ServiceSession draft = new ServiceSession()
                    {
                        GateSessionKey = gateSessionKey,
                        LastAccess     = DateTime.Now,
                        Login          = login,
                        SenderName     = senderName,
                        ClientId       = client.Id.Value.ToString(),
                        UserId         = ((Guid)mu.ProviderUserKey).ToString(),
                        DebtingType    = client.DebtingType
                    };
                    draft = _sessionManager.GetSession(draft);
                    if (draft != null)
                    {
                        result = draft.SessionKey;
                    }
                }
            }
            return(result);
        }
Exemple #3
0
 public UnitOfWork(ApiContext context)
 {
     this.context = context;
     User         = new UserRepo(context);
     Client       = new ClientRepo(context);
     UserClient   = new UserClientRepo(context);
 }
Exemple #4
0
        public void TestGetClient()
        {
            //Arrange

            ClientRepo clientRepo = new ClientRepo();

            var expected = new Client(1)
            {
                Addressemail = "*****@*****.**",
                Name         = "Artur",
                Surname      = "Sury"
            };


            //Act

            var current = clientRepo.GetClient(1);

            //Asserts

            Assert.AreEqual(expected.ClientID, current.ClientID);
            Assert.AreEqual(expected.Addressemail, current.Addressemail);
            Assert.AreEqual(expected.Name, current.Name);
            Assert.AreEqual(expected.Surname, current.Surname);
        }
Exemple #5
0
        public HttpResponseMessage EditClientDetails(Client client)
        {
            HttpResponseMessage response = null;

            try
            {
                if (client != null)
                {
                    Client existingInstance = ClientRepo.GetClientById(client.id);
                    if (existingInstance != null)
                    {
                        ClientRepo.EditClient(client);
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Client details Updated successfully!", "Client details Updated successfully!"));
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_202", " Client ID does not exists", "Invalid Client ID"));
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_102", "Invalid Input", "Please check input Json"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(response);
        }
Exemple #6
0
        public ActionResult Create(CreateWorkDone model)
        {
            try
            {
                Client   client   = new ClientRepo(context).GetById(model.ClientId);
                WorkType workType = new WorkTypeRepo(context).GetById(model.WorkTypeId);

                // Create an instance of the work done with the client and work
                // type
                WorkDone workDone = new WorkDone(0, client, workType);

                var wRepo = new WorkDoneRepo(context);
                wRepo.Insert(workDone);
                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException ex)
            {
                HandleDbUpdateException(ex);
            }

            // Create a view model
            CreateWorkDone viewModel = new CreateWorkDone();

            viewModel.PopulateSelectLists(context);

            viewModel.ClientId   = model.ClientId;
            viewModel.WorkTypeId = model.WorkTypeId;
            return(View("Create", viewModel));
        }
Exemple #7
0
 public ActionResult Login(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         ClientRepo cl     = new ClientRepo();
         Client     client = cl.FindClient(model.Name, model.Password);
         if (client != null)
         {
             HttpCookie cookie = new HttpCookie("Auth");
             cookie["AuthUser"] = model.Name;
             cookie["UserID"]   = client.Id.ToString();
             cookie.Expires     = DateTime.Now.AddDays(1);
             Response.Cookies.Add(cookie);
             Session.Clear();
             return(PartialView("Logon"));
         }
         else
         {
             return(JavaScript("(alert('Unknown user!'))"));
         }
     }
     else
     {
         return(PartialView());
     }
 }
Exemple #8
0
        public HttpResponseMessage GetClientById(int client_id)//c_id client_id
        {
            HttpResponseMessage response = null;

            try
            {
                if (client_id != 0)
                {
                    ClientModel existinginstance = ClientRepo.GetClientDetailsById(client_id);
                    if (existinginstance != null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Success", existinginstance));
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_202", "Client ID doesnot exists", "Client ID doesnot exists"));
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_102", "Invalid Input", "Please check input Json"));
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(response);
        }
Exemple #9
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            base.OnActionExecuting(actionContext);
            string sToken = "bla";
            HttpResponseMessage responeMsg = new HttpResponseMessage();
            ClientRepo          repo       = new ClientRepo();
            Client client = null;

            if (actionContext.Request.Headers.Contains(sToken))
            {
                IEnumerable <string> headerValues = actionContext.Request.Headers.GetValues(sToken);
                string token = headerValues.FirstOrDefault();
                client = repo.Load(Int32.Parse(token));
                if (client == null)
                {
                    responeMsg.StatusCode   = HttpStatusCode.Forbidden;
                    responeMsg.ReasonPhrase = "Invalid or expired auth token";
                }
                else
                {
                    responeMsg.StatusCode   = HttpStatusCode.OK;
                    responeMsg.ReasonPhrase = "Token validated";
                    responeMsg.Content      = new StringContent(client.Id.ToString());
                }
            }
            else
            {
                responeMsg.StatusCode   = HttpStatusCode.Forbidden;
                responeMsg.ReasonPhrase = "No token";
            }
            actionContext.Response = responeMsg;
        }
Exemple #10
0
 public UnitOfWork(ApiContext context)
 {
     this.context = context;
     Credential   = new CredentialRepo(context);
     Client       = new ClientRepo(context);
     Logsheet     = new LogsheetRepo(context);
 }
        public void PopulateSelectLists(Context context)
        {
            ClientRepo   cRepo  = new ClientRepo(context);
            WorkTypeRepo wtRepo = new WorkTypeRepo(context);

            Clients   = cRepo.GetClients();
            WorkTypes = wtRepo.GetWorkTypes();
        }
Exemple #12
0
 public Task <ClientRepo> AddClient(ClientRepo newClient)
 {
     return(Task.Run(() =>
     {
         Thread.Sleep(2000);
         newClient.ClientId = Guid.NewGuid();
         _clients.Add(newClient);
         return newClient;
     }));
 }
 public ServiceProviderTokenInfoForm(int _clientID, string _clientName)
 {
     InitializeComponent();
     clientName        = _clientName;
     clientId          = _clientID;
     this.Text         = "Client Service Form:" + _clientName;
     _clientRepo       = new ClientRepo();
     tokenRepo         = new TokenRepo();
     this.FormClosing += ServiceProviderTokenInfoForm_FormClosing;
 }
 public ServiceHomeForm()
 {
     InitializeComponent();
     this.Load   += ServiceHomeForm_Load;
     _serviceRepo = new ServiceRepo();
     clientRepo   = new ClientRepo();
     _tokenRepo   = new TokenRepo();
     gvRunningTokens.AutoSizeColumnsMode   = DataGridViewAutoSizeColumnsMode.DisplayedCells;
     gvUpcommingTokens.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
 }
        private static Client GetClientFromDb(string clientId)
        {
            Client client;

            using (var appDbContext = new AppDatabaseContext())
            {
                client = new ClientRepo(appDbContext).GetById(clientId);
            }

            return(client);
        }
        public ActionResult Edit(int id)
        {
            var    repository = new ClientRepo(context);
            Client client     = repository.GetById(id);

            var formModel = new EditClient();

            formModel.Id          = client.Id;
            formModel.IsActivated = client.IsActive;
            formModel.Name        = client.Name;

            return(View("Edit", formModel));
        }
        public void testgetclient()
        {
            var context = CreateContext.getNewContext("TestingDB");
            var repo    = new ClientRepo(context);
            var VC      = new VenueController(repo);
            IEnumerable <Clients> Result = VC.Get();

            string[] names = { "Alabama Coffee", "Brad's Bistro" };
            int      count = 0;

            foreach (Clients c in Result)
            {
                Assert.Equal(c.ClientName, names[count]);
                count++;
            }
        }
        public ActionResult Edit(int id, EditClient formModel)
        {
            var repository = new ClientRepo(context);

            try
            {
                var client = new Client(id, formModel.Name, formModel.IsActivated);
                repository.Update(client);
                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException ex)
            {
                HandleDbUpdateException(ex);
            }

            return(View("Edit", formModel));
        }
Exemple #19
0
        public Task <ClientRepo> UpdateClient(ClientRepo newClient)
        {
            return(Task.Run(() =>
            {
                Thread.Sleep(2000);

                var existingClient = _clients.FirstOrDefault(x => x.ClientId == newClient.ClientId);
                if (existingClient == null)
                {
                    return null;
                }
                var index = _clients
                            .IndexOf(existingClient);
                _clients[index] = newClient;
                return newClient;
            }));
        }
Exemple #20
0
        internal void ValidateRegistration(SqlCommand connection)
        {
            foreach (UserType userType in GetPermissions())
            {
                if (userType == UserType.Cliente)
                {
                    Client client = ClientRepo.FindClient(username, connection);
                    this.client = client != null ? client : CreateClient();
                }

                if (userType == UserType.Proveedor)
                {
                    Provider provider = ProviderRepo.FindProvider(username, connection);
                    this.provider = provider != null ? provider : CreateProvider();
                }
            }
        }
        public ActionResult Create(CreateClient formModel)
        {
            var repository = new ClientRepo(context);

            try
            {
                var client = new Client(0, formModel.Name, formModel.IsActivated);
                repository.Insert(client);
                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException ex)
            {
                HandleDbUpdateException(ex);
            }

            return(View("Create", formModel));
        }
Exemple #22
0
        private void InitFields()
        {
            MembershipUser user = _membership.GetUser();

            if (user != null && _loginedUserId.ToString() != user.ProviderUserKey.ToString())
            {
                _loginedUserName = user.UserName;
                _loginedUserId   = new Guid(user.ProviderUserKey.ToString());
                _realClient      = ClientRepo.GetClientProjected(_loginedUserId);
                if (_realClient != null)
                {
                    _repo = RepoGetter <ClientRepo> .Get(_loginedUserName, _realClient.Id, GetOperationalClientId().Value);

                    _currentBallance = _realClient.Ballance;
                }
            }
        }
Exemple #23
0
        public HttpResponseMessage GetActiveClientList()
        {
            HttpResponseMessage response = null;

            try
            {
                List <ClientModel> Client_List = ClientRepo.GetActiveClientList();
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Success", Client_List));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(response);
        }
 public void Execute()
 {
     try
     {
         ClientRepo.Add(Entity);
         Scope.Complete();
     }
     catch (NullReferenceException e)
     {
         Rollback();
         throw e;
     }
     catch (TransactionException e)
     {
         Rollback();
         throw new InvalidOperationException("Add entity faild ", e);
     }
 }
Exemple #25
0
        public PartialViewResult AddProduct(Product product, HttpPostedFileBase uploadImage1, HttpPostedFileBase uploadImage2, HttpPostedFileBase uploadImage3)
        {
            ClientRepo cl = new ClientRepo();

            if (ModelState.IsValid)
            {
                if (uploadImage1 != null)
                {
                    byte[] imageData1 = null;
                    using (var binaryReader = new BinaryReader(uploadImage1.InputStream))
                    {
                        imageData1 = binaryReader.ReadBytes(uploadImage1.ContentLength);
                    }
                    product.Picture1 = imageData1;
                }
                if (uploadImage2 != null)
                {
                    byte[] imageData2 = null;
                    using (var binaryReader = new BinaryReader(uploadImage2.InputStream))
                    {
                        imageData2 = binaryReader.ReadBytes(uploadImage2.ContentLength);
                    }
                    product.Picture2 = imageData2;
                }
                if (uploadImage3 != null)
                {
                    byte[] imageData3 = null;
                    using (var binaryReader = new BinaryReader(uploadImage3.InputStream))
                    {
                        imageData3 = binaryReader.ReadBytes(uploadImage3.ContentLength);
                    }
                    product.Picture3 = imageData3;
                }
                HttpCookie cookieReq = Request.Cookies["Auth"];
                long       id        = Convert.ToInt64(cookieReq["UserID"]);
                product.OwnerId = cl.FindClient(id).Id;
                pr.AddProduct(product);
                return(PartialView("ShowOwnProducts"));
            }
            else
            {
                return(PartialView());
            }
        }
Exemple #26
0
        public SMSCheckItem CheckSMS(string login, string password, Guid id)
        {
            SMSCheckItem result = null;

            if (Membership.ValidateUser(login, password))
            {
                MembershipUser mu  = Membership.GetUser(login);
                long?          cid = ClientRepo.GetClientProjected((Guid)mu.ProviderUserKey).Id;
                if (cid != null)
                {
                    result = _gateService.CheckSMS(Settings.Default.GateUserName, Settings.Default.GatePassword, id, cid.Value.ToString());
                }
            }
            else
            {
                throw new Exception(Resources.Error_LoginFailed);
            }
            return(result);
        }
Exemple #27
0
 public static Client ToModel(this ClientRepo repoModel)
 {
     return(new Client
     {
         ClientId = repoModel.ClientId,
         Address = new Address
         {
             City = repoModel.Address.City,
             Country = repoModel.Address.Country,
             PostCode = repoModel.Address.PostCode,
             StreetName = repoModel.Address.StreetName,
             StreetNumber = repoModel.Address.StreetNumber
         },
         Name = repoModel.Name,
         Birthday = repoModel.Birthday,
         ClientSince = repoModel.ClientSince,
         Lastname = repoModel.Lastname,
         TACAccepted = repoModel.TACAccepted,
         Type = (ClientTypeEnum)Enum.Parse(typeof(ClientTypeEnum), repoModel.Type.ToString())
     });
 }
Exemple #28
0
        public ActionResult Edit(int id, EditWorkDone formModel)
        {
            var cRepository  = new ClientRepo(context);
            var wRepository  = new WorkTypeRepo(context);
            var wdRepository = new WorkDoneRepo(context);

            try
            {
                Client   cToEdit  = cRepository.GetById(formModel.ClientId);
                WorkType wToEdit  = wRepository.GetById(formModel.WorkTypeId);
                var      workDone = new WorkDone(id, cToEdit, wToEdit, formModel.StartedOn, formModel.EndedOn);
                wdRepository.Update(workDone);
                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException ex)
            {
                HandleDbUpdateException(ex);
            }

            return(View("Edit", formModel));
        }
        static void Main(string[] args)
        {
            var clientId = args.Length > 0 ? args[0] : "client0";

            var client = new ClientRepo (new ServerRef ("http://localhost:31337"), clientId);

            var frankPosts = client.Table<Tweet> ().Where (f => f.From == "Frank");

            var ch = client.Subscribe (frankPosts);

            ch.AllValues += tweets => {
                foreach (var p in tweets) {
                    ShowPost (p);
                }
            };

            ch.BeginGetAll();

            ch.ValueInserted += ShowPost;

            System.Threading.Thread.Sleep (20000);
        }
Exemple #30
0
        public HttpResponseMessage CreateNewClient(Client client)
        {
            HttpResponseMessage Response = null;

            try
            {
                if (client != null)
                {
                    Client existingInstance = ClientRepo.GetExistingClientInstance(client.client_name, client.type_id);
                    if (existingInstance == null)
                    {
                        client.is_active = 1;
                        ClientRepo.CreateNewClient(client);
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_001", "Client added successfully", "Client added successfully"));
                    }
                    else
                    {
                        Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_201", "Client already exists", "Client already exists"));
                    }
                }
                else
                {
                    Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_102", "Failure", "Please check the Json input"));
                }
            }
            catch (DbEntityValidationException DBexception)
            {
                Debug.WriteLine(DBexception.Message);
                Debug.WriteLine(DBexception.GetBaseException());
                Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_190", "Mandatory fields missing", DBexception.Message));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                Debug.WriteLine(exception.GetBaseException());
                Response = Request.CreateResponse(HttpStatusCode.OK, new EMSResponseMessage("EMS_101", "Application Error", exception.Message));
            }
            return(Response);
        }
Exemple #31
0
        public bool NotifyFailed(Guid smsId, string clientId, string distibutionId = null, Dictionary <string, string> additionalParams = null)
        {
            long intClientId;
            bool result = false;

            if (long.TryParse(clientId, out intClientId))
            {
                ClientModel client = ClientRepo.GetClientConcrete(intClientId);
                if (client != null && client.Id.HasValue)
                {
                    if (client.DebtingType == DebtingType.ByDelivered)
                    {
                        if (!additionalParams.ContainsKey(ADEService.EXTERNAL))
                        {
                            long?intDistibutionId = null;
                            if (!string.IsNullOrEmpty(distibutionId))
                            {
                                long dId;
                                if (long.TryParse(distibutionId, out dId))
                                {
                                    intDistibutionId = dId;
                                }
                            }
                            result = BillingProcessor.ResetSMSSend(intClientId, distributionId: intDistibutionId);
                        }
                        else
                        {
                            result = BillingProcessor.ResetSMSSend(intClientId, extDistributionId: distibutionId);
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }