Esempio n. 1
0
        public void PostTest()
        {
            var responseResult = WebApiClient.HttpGet(ApiEnvironment.BossComment_Search_Endpoint);

            Assert.AreEqual(HttpStatusCode.OK, responseResult.StatusCode);
            Assert.IsNotNullOrEmpty(responseResult.Content);

            var summary = responseResult.Content.ConvertEntity <IList <BossCommentEntity> >();


            var entity = new BossCommentEntity()
            {
                TargetName      = string.Format("Name{0}", TestHelper.GetRndString()),
                TargetIDCard    = string.Format("IDcard{0}", TestHelper.GetRndString()),
                TargetJobTitle  = string.Format("title{0}", TestHelper.GetRndString()),
                WorkAbility     = TestHelper.GetRndNumber(0, 5),
                WorkAchievement = TestHelper.GetRndNumber(0, 5),
                WorkManner      = TestHelper.GetRndNumber(0, 5),
                Text            = string.Format("title{0}", TestHelper.GetRndString()),
                Voice           = TestHelper.GetTestImageStream(),
                Images          = new string[TestHelper.GetRndNumber(1, 4)]
            };

            for (var i = 0; i < entity.Images.Length; i++)
            {
                entity.Images[i] = TestHelper.GetTestImageStream();
            }

            var responseResult2 = WebApiClient.HttpPost(ApiEnvironment.BossComment_Post_Endpoint, entity);

            Assert.AreEqual(HttpStatusCode.OK, responseResult2.StatusCode);
        }
Esempio n. 2
0
        public long Post([FromBody] BossCommentEntity entity)
        {
            if (null == entity)
            {
                return(-1);
            }
            if (string.IsNullOrEmpty(entity.TargetIDCard))
            {
                return(-1);
            }

            var target = TargetEmploye.FindByIDCard(entity.TargetIDCard);

            if (null == target)
            {
                target          = new TargetEmploye();
                target.RealName = entity.TargetName;
                target.IDCard   = entity.TargetIDCard;
                target.Tags     = new string[] { target.RealName, target.IDCard.Substring(0, target.IDCard.Length > 6 ? 6 : target.IDCard.Length) };
                target.Save();
            }
            else if (target.RealName != entity.TargetName)
            {
                target.RealName = entity.TargetName;
                target.Save();
            }

            var userProfile = MvcContext.Current.UserPassport.Profile;
            var model       = new BossComment();

            model.FillPropertiesFromEntity(entity, true);
            var request = OpenAccountRequest.FindByPassportId(userProfile.PassportId);

            model.EmployeId           = target.EmployeId;
            model.CommentEntId        = 0;// EntInfo.FindByEntName(request.EntName).EntId;
            model.CommentatorId       = userProfile.PassportId;
            model.CommentatorName     = userProfile.RealName;
            model.CommentatorJobTitle = userProfile.CurrentJobTitle;

            var saved = model.Save();

            if (saved && (false == string.IsNullOrEmpty(entity.Voice) || null != entity.Images))
            {
                if (false == string.IsNullOrEmpty(entity.Voice))
                {
                    model.Voice = ImageHelper.SaveBossCommentVoice(model.CommentId, model.CreatedTime, entity.Voice) + "?t=" + DateTime.Now.ToString("yyMMddHHmmssfff");
                }

                if (null != entity.Images && entity.Images.Length > 0)
                {
                    string[] applyImages = null == entity.Images ? null : new string[entity.Images.Length];
                    if (null != entity.Images)
                    {
                        for (var i = 0; i < entity.Images.Length; i++)
                        {
                            var imageUrl = ImageHelper.SaveBossCommentImage(model.CommentId, model.CreatedTime, entity.Images[i]);
                            applyImages[i] = imageUrl + "?t=" + DateTime.Now.ToString("yyMMddHHmmssfff");
                        }
                        model.Images = applyImages;
                    }
                }

                saved = model.Save();
            }

            return(model.CommentId);
        }