示例#1
0
        public async Task <IActionResult> EditLocalUnit([FromBody] LocalUnitEditM data)
        {
            var result = await _editService.EditLocalUnit(data, User.GetUserId());

            if (result != null && result.ContainsKey(nameof(UserAccess.UnauthorizedAccess)))
            {
                return(Forbid());
            }
            return(result == null ? (IActionResult)NoContent() : BadRequest(result));
        }
示例#2
0
        /// <summary>
        /// Local unit editing method
        /// </summary>
        /// <param name = "data"> Data </param>
        /// <param name = "userId"> User Id </param>
        /// <returns> </returns>
        public async Task <Dictionary <string, string[]> > EditLocalUnit(LocalUnitEditM data, string userId)
        => await EditUnitContext <LocalUnit, LocalUnitEditM>(
            data,
            v => v.RegId ?? 0,
            userId,
            unit =>
        {
            if (_deletedStatusId != null && unit.UnitStatusId == _deletedStatusId)
            {
                _deleteService.CheckBeforeDelete(unit, true);
            }

            if (_liquidateStatusId != null && unit.UnitStatusId == _liquidateStatusId)
            {
                var legalUnit = _dbContext.LegalUnits.Include(x => x.LocalUnits).FirstOrDefault(x => unit.LegalUnitId == x.RegId && !x.IsDeleted);
                if (legalUnit != null && legalUnit.LocalUnits.Where(x => !x.IsDeleted && x.UnitStatusId != _liquidateStatusId.Value).ToList().Count == 0)
                {
                    throw new BadRequestException(nameof(Resource.LiquidateLegalUnit));
                }
            }
            return(Task.CompletedTask);
        });