コード例 #1
0
        public VincereSharpTestsBase()
        {
            var          currentDirectory = Directory.GetCurrentDirectory();
            const string webTestLoc       = "../../../../WebTest";
            var          settingsFileLoc  = $"{ webTestLoc }/RefreshToken.txt";

            var config = new ConfigurationBuilder()
                         .AddJsonFile(Path.GetFullPath($"{ webTestLoc }/appsettings.json"))
                         .Build();

            if (!File.Exists(settingsFileLoc))
            {
                throw new FileNotFoundException("Run the web project to login first so that RefreshToken.txt is created");
            }

            var clientId     = config["Vincere:ClientId"];
            var apiKey       = config["Vincere:ApiKey"];
            var domainId     = config["Vincere:DomainId"];
            var refreshToken = File.ReadAllText(settingsFileLoc);

            client = new VincereClient(clientId, apiKey, domainId)
            {
                RefresherToken = refreshToken
            };
        }
コード例 #2
0
        // GET: Contacts/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                var model = await VincereClient.GetContactAsync(id);

                return(View(model));
            }
            catch (HttpRequestException ex)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
コード例 #3
0
        public async Task <ActionResult> Delete(int id, IFormCollection collection)
        {
            try
            {
                var response = await VincereClient.DeleteContactAsync(id);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                TempData["Message"] = ex.Message;
                return(View());
            }
        }
コード例 #4
0
        public async Task <ActionResult> Delete(int id, IFormCollection collection)
        {
            try
            {
                var response = await VincereClient.DeleteContactAsync(id);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                throw;
                return(View());
            }
        }
コード例 #5
0
        // GET: Company
        public async Task <ActionResult> Index([FromQuery] string searchText = "")
        {
            try
            {
                var model = await VincereClient.SearchCompaniesAsync(searchText);

                return(View(model));
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(Index), "Home"));

                throw;
            }
        }
コード例 #6
0
        public async Task <ActionResult> Edit(int id, [FromForm] Contact contact)
        {
            try
            {
                // TODO: Add update logic here
                var result = await VincereClient.UpdateContactAsync(contact, id);

                TempData["Message"] = "Contact Updated";
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
コード例 #7
0
        public static VincereClient GetClient(this Controller controller, VincereConfig config)
        {
            VincereClient obj;

            if (controller.HttpContext.Session.Keys.Contains("VincereClient"))
            {
                var str = controller.HttpContext.Session.GetString("VincereClient");
                obj        = JsonConvert.DeserializeObject <VincereClient>(str);
                obj.Config = config;
            }
            else
            {
                obj = new VincereClient(config);
            }
            return(obj);
        }
コード例 #8
0
        public async Task <ActionResult> Create([FromForm] Contact contact)
        {
            try
            {
                contact.RegistrationDate = DateTime.Now;
                var result = await VincereClient.AddContactAsync(contact);

                TempData["Message"] = "Contact Created";
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(View());
            }
        }
コード例 #9
0
        public static void SetClient(this Controller controller, VincereClient value)
        {
            var str = JsonConvert.SerializeObject(value);

            controller.HttpContext.Session.SetString("VincereClient", str);
        }
コード例 #10
0
        // GET: Contacts/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            var model = await VincereClient.GetContactAsync(id);

            return(View(model));
        }