コード例 #1
0
        public ActionResult GetToDo(int id)
        {
            var viewModel = new ToDoViewModel();

            ViewBag.ToDoId = id;
            ViewData.Add("selecteToDo", id);
            var toDoService = new WCFService.ToDoService();
            var request     = new GetToDoRq();

            request.Id = id;
            var todoResponse = toDoService.GetToDoById(request);

            ViewBag.ToDoName       = todoResponse.Name;
            viewModel.ToDoTaskList = new List <ToDoTaskViewModel>();
            foreach (var item in todoResponse.ToDoTaskList)
            {
                viewModel.ToDoTaskList.Add(new ToDoTaskViewModel
                {
                    Id             = item.Id,
                    ToDoId         = item.Id,
                    TaskName       = item.TaskName,
                    Completed      = item.Completed,
                    Description    = item.Description,
                    ExpireDateTime = item.ExpireDateTime
                });
            }
            viewModel.Name   = todoResponse.Name;
            viewModel.Id     = id;
            ViewBag.ToDoName = todoResponse.Name;
            LayoutModel layoutModel = new LayoutModel <ToDoViewModel>(viewModel, ViewBag.ToDoName, viewModel.Id);

            return(View(layoutModel));
        }
コード例 #2
0
        public ActionResult Register(FormCollection formCollection)
        {
            //Get formCollection in key parameters
            var name     = formCollection.Get("firstName") ?? "";
            var email    = formCollection.Get("email") ?? "";
            var password = formCollection.Get("password") ?? "";

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                ViewBag.successMessage = "Error";
                return(View());
            }
            var requestRegisterRq = new TODOListApplication.ServiceModel.Account.RegisterRq();

            requestRegisterRq.Name     = name;
            requestRegisterRq.Email    = email;
            requestRegisterRq.Password = password;
            WCFService.AccountService accountServiceClient = new WCFService.AccountService();
            WCFService.ToDoService    toDoService          = new WCFService.ToDoService();

            var result = accountServiceClient.Register(requestRegisterRq);

            toDoService.AddToDo(new AddToDoRq {
                Name = "Welcome ToDo List", UserId = result.UserId
            });
            ViewBag.successMessage = "Success";

            return(View());
        }
コード例 #3
0
        public JsonResult DeleteToDoTask(int id)
        {
            var toDoService  = new WCFService.ToDoService();
            var todoResponse = toDoService.DeleteTodoTaskById(id);

            return(Json(todoResponse, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public JsonResult AddToDoTask(AddToDoTaskRq request)
        {
            var userId = GetSession.UserId;

            request.ExpireDateTime = Convert.ToDateTime(request.ExpireDateTimeString);
            var toDoService = new WCFService.ToDoService();


            toDoService.AddToDoTask(request);
            return(Json("", JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public ActionResult Add(FormCollection formCollection)
        {
            var userId      = GetSession.UserId;
            var toDoService = new WCFService.ToDoService();
            var request     = new AddToDoRq {
                Name = formCollection.Get("name") ?? "", UserId = userId
            };
            var result = toDoService.AddToDo(request);

            ViewBag.RedirectToDoId = result.ToDoId;
            return(RedirectToAction("GetToDo", new { id = result.ToDoId }));
        }
コード例 #6
0
        public ActionResult GetToDoList()
        {
            var userId       = GetSession.UserId;
            var viewModel    = new ToDoListViewModel();
            var toDoService  = new WCFService.ToDoService();
            var todoResponse = toDoService.GetToDoList(new GetToDoListRq {
                UserId = userId
            });

            viewModel.ToDoList = new List <TodoVModel>();

            foreach (var item in todoResponse.ToDoList)
            {
                viewModel.ToDoList.Add(new TodoVModel {
                    Id = item.Id, Name = item.Name
                });
            }

            return(PartialView("_GetToDoList", viewModel));
        }
コード例 #7
0
        public ActionResult GetToDoPage(int id, string filterText = null)
        {
            var viewModel   = new ToDoViewModel();
            var toDoService = new WCFService.ToDoService();
            var request     = new GetToDoRq();

            if (!string.IsNullOrEmpty(filterText) && filterText.Equals("completedTask"))
            {
                request.CompletedTask = true;
            }
            else if (!string.IsNullOrEmpty(filterText) && filterText.Equals("expiredTask"))
            {
                request.ExpireDate = true;
            }
            request.Id = id;

            var todoResponse = toDoService.GetToDoById(request);

            viewModel.Id           = todoResponse.Id;
            viewModel.Name         = todoResponse.Name;
            viewModel.ToDoTaskList = new List <ToDoTaskViewModel>();
            foreach (var item in todoResponse.ToDoTaskList)
            {
                viewModel.ToDoTaskList.Add(new ToDoTaskViewModel
                {
                    Id             = item.Id,
                    ToDoId         = item.Id,
                    TaskName       = item.TaskName,
                    Completed      = item.Completed,
                    Description    = item.Description,
                    ExpireDateTime = item.ExpireDateTime
                });
            }

            ViewBag.ToDoName = todoResponse.Name;
            ViewBag.ToDoId   = id;
            LayoutModel layoutModel = new LayoutModel <ToDoViewModel>(viewModel, ViewBag.ToDoName, viewModel.Id);

            return(PartialView("_ToDoList", viewModel));
        }
コード例 #8
0
        public ActionResult Login(FormCollection formCollection)
        {
            //Get formCollection in key parameters
            var email    = formCollection.Get("email") ?? "";
            var password = formCollection.Get("password") ?? "";

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                ViewBag.IsSuccess = false;
                ViewBag.Message   = "Please fill in the required fields.";
                return(View());
            }
            var requestRegisterRq = new TODOListApplication.ServiceModel.Account.LoginRq();

            requestRegisterRq.Email    = email;
            requestRegisterRq.Password = password;
            //WCF Service call.
            WCFService.AccountService accountServiceClient = new WCFService.AccountService();
            var result = accountServiceClient.Login(requestRegisterRq);

            if (result.IsSuccess == false)
            {
                ViewBag.IsSuccess = false;
                ViewBag.Message   = result.Message;
                return(View());
            }
            else
            {
                FormsAuthentication.SetAuthCookie(email, true);

                HttpCookie cookie = new HttpCookie("userId");
                cookie.Values["userId"] = result.UserId.ToString();
                cookie.Expires          = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookie);

                var session = new Session();
                session.UserId          = result.UserId;
                this.Session["Session"] = (Session)session;
                WCFService.ToDoService toDoService = new WCFService.ToDoService();
                var getAllToDo = toDoService.GetToDoList(new GetToDoListRq {
                    UserId = session.UserId
                });
                var lastItem = 0;
                if (getAllToDo.ToDoList.Count > 0)
                {
                    ToDoModel first = null;
                    foreach (var model in getAllToDo.ToDoList)
                    {
                        first = model;
                        break;
                    }

                    if (first != null)
                    {
                        lastItem = first.Id;
                    }
                }

                return(RedirectToAction("GetToDo", "ToDo", new { id = lastItem }));
            }
            ViewBag.IsSuccess = true;

            return(View());
        }