예제 #1
0
        [Authorize(Policy = "ElectricianAndCarpentry")]//Carpentry Electrician
        public async Task <ResponseMessage <RoleReportForRepairViewModel> > UpdateRoleReportForRepair(long roleReportForRepairId)
        {
            ClaimsPrincipal principal = HttpContext.User;
            string          roleName  = principal.FindFirst(x => x.Type == ClaimTypes.Role).Value;
            string          name      = principal.FindFirst(x => x.Type == ClaimTypes.Name).Value;
            string          jti       = principal.FindFirst(x => x.Type == JwtRegisteredClaimNames.Jti).Value;
            Roles           roles     = await _rolesService.Query(x => x.RoleName.Equals(roleName));

            ReportForRepair reportForRepair = await _reportForRepairService.QueryById(roleReportForRepairId);

            if (reportForRepair.WaitHandle == 0)
            {
                reportForRepair.WorkerId   = Convert.ToInt64(jti);
                reportForRepair.RoleId     = roles.Id;
                reportForRepair.WaitHandle = 1;//1标志表示接受处理
                bool update = await _reportForRepairService.Update(reportForRepair);

                return(update
                    ? new ResponseMessage <RoleReportForRepairViewModel>()
                {
                    Msg = "接单成功",
                    Success = true,
                    Status = 200,
                    ResponseInfo = new RoleReportForRepairViewModel()
                    {
                        UserName = name,
                        Dorm = reportForRepair.Dorm,
                        Tung = reportForRepair.Tung,
                        Desc = reportForRepair.Desc,
                        Layer = reportForRepair.Layer
                    }
                }
                    : new ResponseMessage <RoleReportForRepairViewModel>()
                {
                    Msg = "接单失败",
                    Success = false
                });
            }
            else
            {
                return(new ResponseMessage <RoleReportForRepairViewModel>()
                {
                    Msg = "接单失败,该报修已被接受或已完成维修",
                });
            }
        }
        //[Authorize(Policy = "Admin")]
        public async Task <ResponseMessage <bool> > PostComment([FromBody] CommentViewModel model)
        {
            //string jti = HttpContext.User.FindFirst(x => x.Type == JwtRegisteredClaimNames.Jti).Value;
            //long id = Convert.ToInt64(jti);
            ReportForRepair reportForRepair = await _reportForRepairService.QueryById(model.ReportForRepairId);

            if (reportForRepair != null)
            {
                if (reportForRepair.WaitHandle == 2 && reportForRepair.Evaluate == 0)
                {
                    reportForRepair.Evaluate = model.Evaluate;
                    bool update = await _reportForRepairService.Update(reportForRepair);

                    if (update)
                    {
                        return(new ResponseMessage <bool>()
                        {
                            Msg = "提交评论成功",
                            Status = 200,
                            Success = true,
                            ResponseInfo = update
                        });
                    }
                }
                return(new ResponseMessage <bool>()
                {
                    Msg = "提交评论失败。可能的原因:维修未完成、已提交过评论",
                    Success = false
                });
            }
            return(new ResponseMessage <bool>()
            {
                Msg = "没有该任务",
                Success = false
            });
        }