コード例 #1
0
        public async Task UpdateAsync(int id, BanCanMiaModel model)
        {
            if (model == null)
            {
                throw new ArgumentException();
            }
            var post = await _repoBanCanMia.Query().FirstOrDefaultAsync(x => x.Ma_BanCanMia == id);

            if (post == null)
            {
                throw new MethodAccessException(MessageConstant.POST_NOT_FOUND);
            }

            var postUpdate = mapper.Map(model, post);

            postUpdate.NgayCapNhat  = DateTime.UtcNow;
            postUpdate.CapNhatBoi   = "";// LogedInUserId;
            postUpdate.Ma_BanCanMia = id;

            _repoBanCanMia.Update(postUpdate);
            var saveResult = await unitOfWork.SaveChangesAsync();

            if (saveResult <= 0)
            {
                throw new Exception(MessageConstant.POST_NOT_UPDATE_FAILED);
            }
        }
コード例 #2
0
        public async Task <string> AddAsync(BanCanMiaModel model)
        {
            if (model == null)
            {
                return(string.Empty);
            }

            var post = mapper.Map <BanCanMia>(model);

            post.TaoBoi = post.CapNhatBoi;// = LogedInUserId;

            await _repoBanCanMia.AddAsync(post);

            var saveResult = await unitOfWork.SaveChangesAsync();

            if (saveResult > 0)
            {
                return(post.Ma_BanCanMia + string.Empty);
            }
            return(string.Empty);
        }