예제 #1
0
        public ActionResult Save(ToDoList toDoList)
        {
            List <ToDoList> lst = _toDoListRepository.GetListById(toDoList.ToDoListID).ToList();

            if (lst.Count == 1)
            {
                try
                {
                    IEnumerable <ToDoList> allToDoList = _toDoListRepository.GetListByCreatorByAssignedToUser(lst[0].IDCreator, lst[0].IDExecutor);
                    return(RedirectToAction("../Views/ToDoList/Index.cshtml", allToDoList));
                }
                catch
                {
                    return(View());
                }
            }
            return(View());
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] ToDoShareAddResource toDoShare)
        {
            if (toDoShare == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }
            var userModel = await _sysUserRepository.GetUserByAccountAync(toDoShare.Account);

            if (userModel == null)
            {
                userModel = await _sysUserRepository.GetUserByEmailAync(toDoShare.Account);
            }
            if (userModel == null)
            {
                return(NotFound("用户不存在或已删除"));
            }
            var listModel = await _toDoListRepository.GetListById(toDoShare.ListId);

            if (listModel == null)
            {
                return(NotFound("内容不存在或已删除"));
            }
            if (userModel.Id.Equals(listModel.UserId))
            {
                return(BadRequest("不能分享给自己"));
            }
            var toDoModel = new  ToDoShare();

            toDoModel.Id        = Guid.NewGuid();
            toDoModel.ListId    = listModel.Id;
            toDoModel.UserId    = userModel.Id;
            toDoModel.ShareTime = DateTime.Now;
            _toDoShareRepository.AddToDoShare(toDoModel);
            if (!await _unitOfWork.SaveAsync())
            {
                throw new Exception("Error occurred when adding");
            }
            _mailService.send(new MailOptions()
            {
                isbodyHtml = false, mailBody = $"有用户分享了待办列表《{listModel.Title}》给你", mailTitle = "待办列表分享", recipientArry = new string[1] {
                    userModel.Email
                }
            });
            return(Ok(toDoShare));
        }