Example #1
0
        public async Task <int> CreateOrUpdate(LoaiHoSoDto input)
        {
            if (input.Id > 0)
            {
                // update
                var updateData = await _LoaiHoSoRepos.GetAsync(input.Id);

                input.MapTo(updateData);
                await _LoaiHoSoRepos.UpdateAsync(updateData);

                return(updateData.Id);
            }
            else
            {
                try
                {
                    var insertInput = input.MapTo <LoaiHoSo>();
                    int id          = await _LoaiHoSoRepos.InsertAndGetIdAsync(insertInput);

                    await CurrentUnitOfWork.SaveChangesAsync();

                    return(id);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Example #2
0
        public async Task <int> CreateOrUpdateHanXuLy(LoaiHoSoDto input)
        {
            if (input.ThuTucId > 0)
            {
                // update
                var updateData = await _LoaiHoSoHanXuLyRepos.FirstOrDefaultAsync(x => x.ThuTucId == input.ThuTucId);

                if (updateData != null)
                {
                    updateData.JsonHanXuLy = input.JsonHanXuLy;
                    await _LoaiHoSoHanXuLyRepos.UpdateAsync(updateData);

                    return(updateData.Id);
                }
                else
                {
                    try
                    {
                        var insertInput = new LoaiHoSo_HanXuLy();
                        insertInput.ThuTucId    = input.ThuTucId;
                        insertInput.JsonHanXuLy = input.JsonHanXuLy;
                        int id = await _LoaiHoSoHanXuLyRepos.InsertOrUpdateAndGetIdAsync(insertInput);

                        await CurrentUnitOfWork.SaveChangesAsync();

                        return(id);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(1);
        }