Exemplo n.º 1
0
        public async Task <JsonResult> UpdateDraft(MCredit_TempProfileAddModel model)
        {
            if (model == null || model.Id <= 0)
            {
                return(ToJsonResponse(false, "Dữ liệu không hợp lệ"));
            }
            var profile = _mapper.Map <MCredit_TempProfile>(model);

            profile.UpdatedBy = GlobalData.User.IDUser;
            var isAdmin = await _rpEmployee.CheckIsAdmin(GlobalData.User.IDUser);

            profile.Status = isAdmin ? model.Status: (int)MCreditProfileStatus.Submit;
            await _rpLog.InsertLog("mcredit-UpdateDraft", model.Dump());

            var result = await _rpMCredit.UpdateDraftProfile(profile);

            if (!result)
            {
                return(ToJsonResponse(result, "Lỗi cập nhật"));
            }

            if (!string.IsNullOrWhiteSpace(model.LastNote))
            {
                GhichuModel note = new GhichuModel
                {
                    UserId      = GlobalData.User.IDUser,
                    HosoId      = model.Id,
                    Noidung     = model.LastNote,
                    CommentTime = DateTime.Now,
                    TypeId      = (int)NoteType.MCreditTemp
                };
                await _rpNote.AddNoteAsync(note);
            }
            var peopleCanView = await _rpEmployee.GetPeopleIdCanViewMyProfile(GlobalData.User.IDUser);

            if (peopleCanView != null && peopleCanView.Any())
            {
                peopleCanView.Add(GlobalData.User.IDUser);
                peopleCanView.Add(1); //admin
                var ids = string.Join(".", peopleCanView);
                await _rpMCredit.InsertPeopleWhoCanViewProfile(model.Id, ids);
            }
            //var obj = _mapper.Map<MCProfilePostModel>(profile);
            //var result = await _svMCredit.CreateProfile(obj, GlobalData.User.IDUser);
            return(ToJsonResponse(true, ""));
        }