Пример #1
0
        public bool UpdateAccess(AccessInDTO access)
        {
            try
            {
                var currentAccess = _accessRepository.FindByID(access.AccessId ?? Guid.Empty);

                if (currentAccess == null)
                {
                    return(false);
                }

                var accessExists = _accessRepository.FindAll().Any(x => x.Name.ToLower() == access.Name.ToLower() && access.AccessId != access.AccessId);

                if (accessExists)
                {
                    return(false);
                }

                currentAccess.Name        = access.Name;
                currentAccess.Description = access.Description;
                currentAccess.CreatedBy   = null;
                currentAccess.Category    = access.Category != null ? access.Category : String.Empty;
                currentAccess.ModifiedOn  = Localization.GetUTCDateNow();
                currentAccess.ModifiedBy  = null;
                _accessRepository.Update(currentAccess);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(true);
        }
Пример #2
0
        public async Task <AccessResponse> UpdateAsync(int code, Access access)
        {
            try
            {
                var exist = await _accessRepository.FindByIdAsync(code);

                AccessResponse response = exist == null ? new AccessResponse($"Access {code} not found") : new AccessResponse(exist);

                exist.CodeControl = access.CodeControl != 0 ? access.CodeControl : exist.CodeControl;

                exist.CodeDevice = access.CodeDevice != 0 ? access.CodeDevice : exist.CodeDevice;

                _accessRepository.Update(exist);
                await _unitOfWork.CompleteAsync();

                return(response);
            }
            catch (Exception e)
            {
                return(new AccessResponse($"An error occurred when updating the access: { e.Message }"));
            }
        }
Пример #3
0
 public Access Update(Access request)
 {
     return(_AccessRepository.Update(request));
 }