public ActionResult Login(Account account)
        {
            UriApiBuilder.SetUrlPathWithParam("Accounts", "GetAccount", "email", $"{account.Email}");
            WebRequest request = WebRequest.Create(UriApiBuilder.GetUri());

            request.ContentType = "application/json; charset=utf-8";

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (StreamReader dataStream = new StreamReader(response.GetResponseStream()))
                    {
                        Account gottenAccount = JsonConvert.DeserializeObject <Account>(dataStream.ReadToEnd());
                        if (gottenAccount.Name.Equals(account.Name))
                        {
                            SessionPersiter.Account = gottenAccount;
                            return(RedirectToAction("Innexys"));
                        }
                        else
                        {
                            ViewBag.Error = "The Name does not match this email";
                            return(View("Login"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = "This Account does not exists";
                return(View("Login"));
            }
        }
Exemple #2
0
        public ActionResult Create(Task newTask)
        {
            if (!SessionPersiter.Account.Tasks.Any((task) => task.Subject.Equals(newTask.Subject)))
            {
                newTask.AccountId = SessionPersiter.Account.Id;

                HttpClient clientRequest = new HttpClient();

                HttpContent reqContent = new StringContent(JsonConvert.SerializeObject(newTask),
                                                           Encoding.UTF8, "application/json");

                UriApiBuilder.SetUrlPath("Tasks", "CreateTask");

                clientRequest.PostAsync(UriApiBuilder.GetUri(), reqContent).
                ContinueWith((createdTask) => createdTask.Result.EnsureSuccessStatusCode());

                SessionPersiter.Account.Tasks.Add(newTask);

                reqContent = new StringContent(JsonConvert.SerializeObject(SessionPersiter.Account),
                                               Encoding.UTF8, "application/json");

                UriApiBuilder.SetUrlPath("Accounts", "UpdateAccount");

                clientRequest.PutAsync(UriApiBuilder.GetUri(), reqContent).
                ContinueWith((updatedAccount) => updatedAccount.Result.EnsureSuccessStatusCode());

                UriApiBuilder.SetUrlPath("Tasks", "GetLastTaskId");

                WebRequest request = WebRequest.Create(UriApiBuilder.GetUri());
                request.ContentType = "application/json; charset=utf-8";

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (StreamReader dataStream = new StreamReader(response.GetResponseStream()))
                    {
                        SessionPersiter.Account.Tasks.Last().Id      = JsonConvert.DeserializeObject <int>(dataStream.ReadToEnd()) + 1;
                        SessionPersiter.Account.Tasks.Last().Account = SessionPersiter.Account;
                    }
                }

                return(RedirectToAction("Innexys", "Account"));
            }
            else
            {
                ViewBag.Error = "This task already exists";
                return(RedirectToAction("Create"));
            }
        }
        public ActionResult Edit(Account account)
        {
            HttpClient  clientPutRequest = new HttpClient();
            HttpContent putContent       = new StringContent(JsonConvert.SerializeObject(account),
                                                             Encoding.UTF8, "application/json");

            UriApiBuilder.SetUrlPath("Accounts", "UpdateAccount");

            clientPutRequest.PutAsync(UriApiBuilder.GetUri(), putContent).
            ContinueWith((updatedAccount) => updatedAccount.Result.EnsureSuccessStatusCode());

            SessionPersiter.Account.Name     = account.Name;
            SessionPersiter.Account.Email    = account.Email;
            SessionPersiter.Account.Phone    = account.Phone;
            SessionPersiter.Account.Position = account.Position;

            return(RedirectToAction("Innexys", "Account"));
        }
        public ActionResult Innexys()
        {
            UriApiBuilder.SetUrlPath("Accounts", "GetAccounts");

            WebRequest request = WebRequest.Create(UriApiBuilder.GetUri());

            request.ContentType = "application/json; charset=utf-8";

            ICollection <Account> accounts;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (StreamReader dataStream = new StreamReader(response.GetResponseStream()))
                {
                    accounts = JsonConvert.DeserializeObject <ICollection <Account> >(dataStream.ReadToEnd());
                }
            }
            return(View(accounts));
        }
        public ActionResult Register(Account account)
        {
            UriApiBuilder.SetUrlPathWithParam("Accounts", "GetAccount", "email", $"{account.Email}");

            WebRequest request = WebRequest.Create(UriApiBuilder.GetUri());

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    ViewBag.Error = "This Account exists, try another email";
                    return(View("Register"));
                }
            }
            catch (Exception)
            {
                HttpClient  clientPostRequest = new HttpClient();
                HttpContent postContent       = new StringContent(JsonConvert.SerializeObject(account),
                                                                  Encoding.UTF8, "application/json");

                UriApiBuilder.SetUrlPath("Accounts", "CreateAccount");

                clientPostRequest.PostAsync(UriApiBuilder.GetUri(), postContent).
                ContinueWith((createdAccount) => createdAccount.Result.EnsureSuccessStatusCode());

                UriApiBuilder.SetUrlPath("Accounts", "GetLastRegisteredAccount");
                request             = WebRequest.Create(UriApiBuilder.GetUri());
                request.ContentType = "application/json; charset=utf-8";

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (StreamReader dataStream = new StreamReader(response.GetResponseStream()))
                    {
                        SessionPersiter.Account = JsonConvert.DeserializeObject <Account>(dataStream.ReadToEnd());
                    }
                }

                return(RedirectToAction("Innexys"));
            }
        }
Exemple #6
0
        public ActionResult EditTask(Task task)
        {
            Task exisitngtask = SessionPersiter.Account.Tasks.FirstOrDefault((exisitngTask) => exisitngTask.Id == task.Id);

            exisitngtask.Subject     = task.Subject;
            exisitngtask.StartDate   = task.StartDate;
            exisitngtask.EndDate     = task.EndDate;
            exisitngtask.Description = task.Description;
            exisitngtask.Category    = task.Category;

            HttpClient clientRequest = new HttpClient();

            UriApiBuilder.SetUrlPath("Tasks", "UpdateTask");

            HttpContent reqContent = new StringContent(JsonConvert.SerializeObject(exisitngtask),
                                                       Encoding.UTF8, "application/json");

            clientRequest.PutAsync(UriApiBuilder.GetUri(), reqContent).
            ContinueWith((updateTask) => updateTask.Result.EnsureSuccessStatusCode());

            return(RedirectToAction("Innexys", "Account"));
        }