Esempio n. 1
0
        /// <summary>
        /// 保存岗位信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ApiResult <bool> Save(DutyPost model, UserInfo userInfo)
        {
            ApiResult <bool> result = new ApiResult <bool>();

            try
            {
                using (CommonDbContext db = new CommonDbContext())
                {
                    if (string.IsNullOrEmpty(model.PostId))
                    {
                        model.PostId      = GuidHelper.GetSeqGUID();
                        model.CreatedTime = DateTime.Now;
                        model.Creater     = userInfo.UserCode;
                        model.Updater     = userInfo.UserCode;
                        model.UpdateTime  = DateTime.Now;
                        db.Set <DutyPost>().Insert(model);
                    }
                    else
                    {
                        model.UpdateTime = DateTime.Now;
                        model.Updater    = userInfo.UserCode;
                        db.Set <DutyPost>().Update(model);
                    }
                    result.Result = db.SaveChanges() > 0;
                    result.Code   = ResultCode.Success;
                }
            }
            catch (Exception e)
            {
                result.Code    = ResultCode.SystemError;
                result.Message = e.ToString();
            }
            return(result);
        }
Esempio n. 2
0
        public async Task <IActionResult> Post(PostViewModel model)
        {
            var duty = await _dutyManager.GetDutyAsync(model.Id);

            if (duty == null)
            {
                return(NotFound());
            }

            var user = await GetCurrentUser();

            if (duty.ClassRoomId != user.ClassRoomId)
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                var post = new DutyPost
                {
                    DutyId  = duty.Id,
                    Content = model.Content,
                    UserId  = user.Id,
                };

                if (await _postManager.CreateAsync(post))
                {
                    var callbackUrl = Url.Page(
                        "/Duty/Details",
                        pageHandler: null,
                        values: new { id = duty.Id },
                        protocol: Request.Scheme);

                    //_mailingCron.Proc(new MassMailing()
                    //{
                    //    ClassRoomId = user.ClassRoomId,
                    //    Distribution = DistributeType.CLASS,
                    //    Email = new Email()
                    //    {
                    //        Title = "Commentaire de devoir",
                    //        Template = "new-post",
                    //        Attachment = new List<KeyValuePair<string, string>>()
                    //        {
                    //            new KeyValuePair<string, string>("{author}", user.GetFullName()),
                    //            new KeyValuePair<string, string>("{content}", duty.Content.Replace("\n", "<br>")),
                    //            new KeyValuePair<string, string>("{subject}", duty.Subject.Name),
                    //            new KeyValuePair<string, string>("{url}", callbackUrl),
                    //        }
                    //    }
                    //});
                }

                return(RedirectToAction("Details", new { id = duty.Id }));
            }

            ViewBag.Duty = duty;
            return(View(model));
        }
Esempio n. 3
0
 public ApiResult <bool> Put([FromBody] DutyPost DutyPost)
 {
     return(DutyPostService.Save(DutyPost, CurrentUserInfo));
 }