Ejemplo n.º 1
0
        public async Task <bool> UpdateDraftAsync(MCredit_TempProfileAddModel model)
        {
            if (model == null || model.Id <= 0)
            {
                return(ToResponse(false, Errors.invalid_data));
            }
            var profile = _mapper.Map <MCredit_TempProfile>(model);

            profile.UpdatedBy = _process.User.Id;

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

            var result = await _rpMCredit.UpdateDraftProfileAsync(profile);

            if (!result.success)
            {
                return(ToResponse(result));
            }

            if (!string.IsNullOrWhiteSpace(model.LastNote))
            {
                var note = new NoteAddModel
                {
                    UserId        = _process.User.Id,
                    ProfileId     = model.Id,
                    Content       = model.LastNote,
                    CommentTime   = DateTime.Now,
                    ProfileTypeId = (int)NoteType.MCreditTemp
                };
                await _rpNote.AddNoteAsync(note);
            }

            return(true);
        }
Ejemplo n.º 2
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, ""));
        }